Hi, I have a table with a column called id, which is an integer.
I am trying to delete a record by passing in the id.
I get an exception error.
i am trying to check that that id exists first, and if it is delete that user..?
Any help, greatly appreciated.
I am trying to delete a record by passing in the id.
I get an exception error.
VB.NET:
Dim dst As New DataSet
If txtIdNum.TextLength > 0 Then
Dim id As Integer = CInt(txtIdNum.Text)
' start of database code here
Me.OleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath & "\mydb.mdb"
Me.OleDbConnection1.Open() ' open connection to database
Me.OleDbSelectCommand1.CommandText = "SELECT * FROM users WHERE id = '" & txtIdNum.Text & "' LIMIT 1"
Me.OleDbSelectCommand1.Connection = OleDbConnection1
OleDbDataAdapter1.Fill(dst, "Users") ' exception happens here
If dst.Tables("Users").Rows.Count = 1 Then
Me.OleDbDeleteCommand1.CommandText = "DELETE FROM users WHERE id = '" & txtIdNum.Text & "' LIMIT 1"
Me.OleDbInsertCommand1.Connection = OleDbConnection1
Me.OleDbInsertCommand1.ExecuteNonQuery()
OleDbDataAdapter1.Fill(dst, "Users")
If dst.Tables("Users").Rows.Count = 1 Then
MessageBox.Show("User with id: " & txtIdNum.Text & " has been deleted")
Else
MessageBox.Show("User with id: " & txtIdNum.Text & " does not exist", "AutoTime: error")
txtIdNum.Focus()
End If
End If
i am trying to check that that id exists first, and if it is delete that user..?
Any help, greatly appreciated.