Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
connection = New SqlConnection(conStr)
If connection.State = ConnectionState.Closed Then
connection.Open()
End If
sql = "SELECT * FROM data"
command = New SqlCommand(sql, connection)
adapter = New SqlDataAdapter(command)
dataSt = New DataSet()
adapter.Fill(dataSt, "data1")
End Sub
sql = "INSERT INTO data( Name, Sur, School)" & _
"VALUES( @name, @sur, @sch)"
command = New SqlCommand(sql, connection)
command.Parameters.Clear()
command.Parameters.AddWithValue("name", TextBox1.Text)
command.Parameters.AddWithValue("sur", TextBox2.Text)
command.Parameters.AddWithValue("sch", TextBox3.Text)
Dim r As Integer = command.ExecuteNonQuery()
If r = 1 Then
MessageBox.Show("บันทึกข้อมูลแล้ว")
'connection.Close()
Form1_Load(sender, e)
Else
MessageBox.Show("เกิดข้อผิดพลาด")
End If