1 Replies - 327 Views - Last Post: 21 January 2013 - 03:36 AM Rate Topic: -----

#1 debranho  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-January 13

This my code all ways delete the all data in the database please help

Posted 21 January 2013 - 03:20 AM

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

Is This A Good Question/Topic? 0
  • +

Replies To: This my code all ways delete the all data in the database please help

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3359
  • View blog
  • Posts: 11,373
  • Joined: 12-December 12

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1