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

            Dim Con As New SqlConnection("Data Source=SAAD-PC\SQLEXPRESS;Initial Catalog=photoshoot;Integrated Security=True")

            cmd.Connection = Con
            cmd.CommandText = "Delete from Customer where Cust_id = '" & Cust_idTextBox.Text & "'"
            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
        End Try
            ' ORIG ------------------------------------------------------------

            cmd = New SqlCommand("select * from Customer", conn)
            Adaptor = New SqlDataAdapter(cmd)
            Adaptor.Fill(dataset, "NewBookingdataset1")
            NewBookingDataGridView.DataSource = dataset.Tables("customer")

        Catch ex As Exception
        End Try
    End If
End Sub
4 Years
Discussion Span
Last Post by M.Waqas Aslam

That is the problem . I can delete the values of customer table but i dont know how to delete the information from grid for the booking table.
i get an error "non execute query connection string not been intialized". please help


in this code you are just dealing with customer table , just you should have one thing always in your mind , always first delete the related record then the main records , for example we have a customer name ali , now we also have 3 records in table books , in order to delete ali from the customer we have to delete 3 records of ali from the table books ,now use same code and just change the query and in query just change the name of table , then after execute the query and deleting the records form the table books then delete record of your perticular customer.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.