hi Every one i am having problem in deleting record from textboxes and gridview. i have customer table and booking table. what i want to do is when i click the delete button the customer and its related booking should be deleted. i have written a code which onlt deletes customer but it doesnt delete the related booking in the data gridview.i am also attaching my screen shot to give a better idea. and here is my code. The textboxes contains the customer information and gridview contains booking information.Cust_id is foregin key in booking table. please help.
Private Sub btnDelCus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelCus.Click
Dim i As Integer
i = MsgBox("Are you sure you want to delete the record?", vbYesNo, "Sweat and Shape Gym")
If i = vbYes Then
Dim conn As New SqlClient.SqlConnection
Dim cmd As New SqlClient.SqlCommand
Dim Adaptor As New SqlClient.SqlDataAdapter
Dim dataset As New DataSet
Try
Dim Con As New SqlConnection("Data Source=SAAD-PC\SQLEXPRESS;Initial Catalog=photoshoot;Integrated Security=True")
Con.Open()
cmd.Connection = Con
cmd.CommandText = "Delete from Customer where Cust_id = '" & Cust_idTextBox.Text & "'"
cmd.ExecuteNonQuery()
MsgBox("Record Deleted!")
Cust_idTextBox.Text = ""
LastNameTextBox.Text = ""
FirstNameTextBox.Text = ""
AddressTextBox.Text = ""
Post_CodeTextBox.Text = ""
TelephoneTextBox.Text = ""
Emp_idTextBox.Text = ""
EmailTextBox.Text = ""
Catch ex As Exception
MsgBox(ex.Message)
End Try
conn.Close()
Try
' ORIG ------------------------------------------------------------
conn.Open()
cmd = New SqlCommand("select * from Customer", conn)
Adaptor = New SqlDataAdapter(cmd)
dataset.Clear()
Adaptor.Fill(dataset, "NewBookingdataset1")
NewBookingDataGridView.DataSource = dataset.Tables("customer")
'---------------------------------------------------------
conn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
NewBookingDataGridView.Refresh()
End If
End Sub