0

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

Attachments booking.jpg 35.53 KB
3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Mitja Bonca
0
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()

Edited by Jx_Man: n/a

0

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())
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.