Hi every one i am having some problem in deleting customer Record. I have also uploading the screen shot of my form. i have customer records in textboxes and booking records in datagridview . i have solved the problem to delete the records in gridview but i want a button which when i click deletes both customer and related booking records. I can do this task using binding navigator cross button but i dont want to use that instead i want to use coding under a button click event please help.here is the screen shot

Dim conn As New SqlConnection("ConnectionStringGoesHere")
    Dim cmd As New SqlCommand
    conn.Open()
    cmd.Connection = conn
    cmd.CommandText = "Delete From bookings where Bk_id = " & CInt(datagridView1.Item(0,datagridView1.CurrentRow.Index).Value.ToString)
    cmd.ExecuteNonQuery()
    conn.Close()

Yep, I would only recommend you to use parametriezed query, so you specify the parameter in additional like of code:

cmd.CommandText = "Delete From bookings where Bk_id = @param1"
cmd.Parameters.Add("@param1", SqlDbType.Int).Value = Integer.Parse(dataGridView1(0, dataGridView1.CurrentRow.Index).Value.ToString())
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.