Dim connection As SqlConnection
Dim adapter As New SqlDataAdapter
Dim sql As String
Dim cmd As SqlCommand
Try
If Not dgvData.CurrentRow.IsNewRow Then
'Query string
sql = "delete from AccountPayable where AP_Date = '" & dgvData.CurrentRow.Cells(0).Value & "'"
'sql connection
connection = New SqlConnection("Data Source=.\sqlexpress;Initial Catalog=FinAccounting;Integrated Security=True")
connection.Open()
'command button
cmd = New SqlCommand(sql, connection)
cmd.ExecuteNonQuery()
dgvData.Rows.Remove(dgvData.CurrentRow)
MessageBox.Show("Record Deleted")
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
1 Replies - 154 Views - Last Post: 21 January 2013 - 03:36 AM
#1
This my code all ways delete the all data in the database please help
Posted 21 January 2013 - 03:20 AM
Replies To: This my code all ways delete the all data in the database please help
#2
Re: This my code all ways delete the all data in the database please help
Posted 21 January 2013 - 03:36 AM
What is the value of dgvData.CurrentRow.Cells(0).Value and what are the values of AP_Date in the table AccountPayable?
Please wrap your code in code-tags; it tells you how to do this directly in the area where you are typing your post.
Please wrap your code in code-tags; it tells you how to do this directly in the area where you are typing your post.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|