Okay, So I'm currently working on my A2 computing project, and I am having slight difficulties updating and saving the data in my database when it is entered on a form in VB. I cannot find any reason why it wouldn't work, but if someone could suggest a better way to do it, it would be great as everything else works. It's in the btnsave at the bottom, and when you click the button on the form it come up with a very unuseful error, which is no help to anyone. Any help would be SO greatly appreciated!
This is the code for the edit details form, where on loading, the customers details which are currently in the database are already there, and they can change things on it and save it to update their details if anything changes.
Public Class EditMyDetails
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim ds As New DataSet
Dim da As New OleDb.OleDbDataAdapter
Dim sql As String
Dim customerdetails As Integer
Dim user As Boolean
Dim rownumber As Integer
Dim failed As Boolean
Private Sub btnhome_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhome.Click
Me.Visible = False
Homepage.Visible = True
End Sub
Private Sub btneditdetails_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneditdetails.Click
Me.Visible = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneditpassword.Click
Me.Visible = False
EditPassword.Visible = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbook.Click
Me.Visible = False
Book.Visible = True
End Sub
Private Sub btncancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancel.Click
Me.Visible = False
Homepage.Visible = True
End Sub
Private Sub btnviewandcancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnviewandcancel.Click
Me.Visible = False
ViewAndOrCancelBookedServices.Visible = True
End Sub
Private Sub EditMyDetails_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source = C:\Users\Nat\Documents\Project.mdb"
con.ConnectionString = dbProvider & dbSource
con.Open()
sql = "SELECT * FROM tbl_CustomerDetails"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "Edit")
con.Close()
'works out which row to get the data from
customerdetails = ds.Tables("Edit").Rows.Count
rownumber = 0
Do Until user = True Or failed = True
If rownumber = customerdetails Then
failed = True
Else
If ds.Tables("Edit").Rows(rownumber).Item(1) = txtfirstname.Text Then
user = True
Else
rownumber = rownumber + 1
End If
End If
Loop
If user = True Then
txtaddress1.Text = ds.Tables("Edit").Rows(rownumber).Item(3)
txtaddress2.Text = ds.Tables("Edit").Rows(rownumber).Item(4)
txttown.Text = ds.Tables("Edit").Rows(rownumber).Item(5)
txtcounty.Text = ds.Tables("Edit").Rows(rownumber).Item(6)
txtPostcode.Text = ds.Tables("Edit").Rows(rownumber).Item(7)
txthomenumber.Text = ds.Tables("Edit").Rows(rownumber).Item(8)
txtmobilenumber.Text = ds.Tables("Edit").Rows(rownumber).Item(9)
txtemailaddress.Text = ds.Tables("Edit").Rows(rownumber).Item(10)
End If
End Sub
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
'saves the newly entered data and updates it
Dim cb As New OleDb.OleDbCommandBuilder(da)
ds.Tables("Edit").Rows(rownumber).Item(3) = txtaddress1.Text
ds.Tables("Edit").Rows(rownumber).Item(4) = txtaddress2.Text
ds.Tables("Edit").Rows(rownumber).Item(5) = txttown.Text
ds.Tables("Edit").Rows(rownumber).Item(6) = txtcounty.Text
ds.Tables("Edit").Rows(rownumber).Item(7) = txtPostcode.Text
ds.Tables("Edit").Rows(rownumber).Item(8) = txthomenumber.Text
ds.Tables("Edit").Rows(rownumber).Item(9) = txtmobilenumber.Text
ds.Tables("Edit").Rows(rownumber).Item(10) = txtemailaddress.Text
'Should update database
da.Update(ds, "Edit")
End Sub
End Class