0

Hi, Im trying to add a code which adds a record for me and then saves it. I am also trying to add a code which deletes the record for me.
So far, my "Add" button, clears the form, which is what I want. Then when I click on save, I get a error. I also get the same error when i Click Delete. This is my code for my "Save" button:

If inc <> -1 Then
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsnewrow As DataRow

dsnewrow = ds.Tables("SuperTronicsWorld").NewRow()
dsnewrow.Item("Customer ID") = txtcustid.Text
dsnewrow.Item("Title") = cbotitle.Text
dsnewrow.Item("First Name") = txtfirstname.Text
dsnewrow.Item("Last Name") = txtsurname.Text
dsnewrow.Item("Company Name") = txtcompanyname.Text
dsnewrow.Item("1st line address") = txtfirstlineadd.Text
dsnewrow.Item("2nd line address") = txtsecondlineadd.Text
dsnewrow.Item("City") = txtcity.Text
dsnewrow.Item("Post Code") = txtpostcode.Text
dsnewrow.Item("Country") = txtcountry.Text
dsnewrow.Item("Tel No") = txttelno.Text
dsnewrow.Item("Bank nane") = lstbank.Text
dsnewrow.Item("Account number") = txtaccno.Text
ds.Tables("SuperTronicsWorld").Rows.Add(dsnewrow)

da.Update(ds, "SuperTronicsWorld")
MsgBox("New Record Successfully appended to the Database!")
btnsave.Enabled() = False
btnadd.Enabled = True
btnedit.Enabled = True
btndelete.Enabled = True
End If
End Sub

This is my code for my Delete button:

Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelete.Click
Dim cb As New OleDb.OleDbCommandBuilder(da)
'message to promt for deletion first
If MessageBox.Show("Are you sure you want to delete this Record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then
MsgBox("Operation Cancelled")
Exit Sub
End If

ds.Tables("SuperTronicsWorld").Rows(inc).Delete()
MaxRows = MaxRows - 1
inc = 0
Navigaterecords()
da.Update(ds, "SuperTronicsWorld")
da.Update(ds, "SuperTronicsWorld")
btnsave.Enabled() = False
btnadd.Enabled = True
btnedit.Enabled = True
btndelete.Enabled = True


End Sub


When I click on save, I get a error which highlights the "da.Update(ds, "SuperTronicsWorld")" in yellow, and it says "Syntax error in INSERT INTO statement."


When I click delete, "txtcustid.Text = ds.Tables("SuperTronicsWorld").Rows(inc).Item(0)" gets highlighted in my "Navigate records" and it says "Deleted row information cannot be accessed through the row."

Please can someone tell me what Im doing wrong?

Thanks alot.

1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by hiz460
0

Sorry I need to put this in VB.Net, please can someone delete this, I will report in VB.NET. Sorry!

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.