Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
OwnerTableAdapter.Insert(txtID.Text, txtOwName.Text, cBoxOwGend.SelectedItem, dateOwBirth.Value.Date, "", txtOwnerPass.Text)
OwnerTableAdapter.Fill(DataPetDataSet.Owner)
Catch ex As Exception
MessageBox.Show(ex.Message, "กรุณาตรวจสอบข้อมูล คุณอาจจะป้อนข้อมูลลผิด")
End Try
txtOwName.Text = ""
cBoxOwGend.Text = ""
dateOwBirth.Value = Now
txtOwSplen.Text = ""
End Sub
อันนี้ Delete ครับ Code (VB.NET)
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'--delete จาก IDowner
If MessageBox.Show("Are you sure to delete?", "Confirm.", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Yes Then
Dim strConnection As String = "Data Source=YYY;Initial Catalog=dataPet;Persist Security Info=True;User ID=sa;Password=123"
Dim IdDelete As String
IdDelete = txtID.Text
Dim strSQL As String = "DELETE FROM Owner WHERE OwnerID='" & IdDelete & "'"
Dim cn As New SqlConnection(strConnection)
Dim cm As New SqlCommand(strSQL, cn)
Dim dr As SqlDataReader
cn.Open()
dr = cm.ExecuteReader
dr.Read()
dr.Close()
cn.Close()
MessageBox.Show("Delete Successfully")
DataGridView1.Refresh()
End If
End Sub