-
update database
Hi All,
I have a weird issue and no access to my past files to help me. I need to update the database, the code i have should work but it is telling me there is an error in my insert command. any ideas?
Code:
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim sql As String
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source = " & My.Settings.path & My.Settings.filename
con.ConnectionString = dbProvider & dbSource
con.Open()
sql = "SELECT * FROM customer"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "customer")
con.Close()
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsNewRow As DataRow
dsNewRow = ds.Tables("customer").NewRow()
dsNewRow.Item("fname") = TextBox1.Text ' update recordds
dsNewRow.Item("lname") = TextBox8.Text
dsNewRow.Item("streetadd") = TextBox7.Text
dsNewRow.Item("suburb") = TextBox6.Text
dsNewRow.Item("postcode") = TextBox5.Text
dsNewRow.Item("phone") = TextBox4.Text
If TextBox3.Text = "" Then
dsNewRow.Item("mobile") = "na"
Else
dsNewRow.Item("mobile") = TextBox3.Text ' if blank make "na"
End If
dsNewRow.Item("email") = TextBox2.Text
Dim asd As Integer
Dim dsa As String
dsa = ComboBox5.Text
asd = dsa
dsNewRow.Item("max") = asd
dsNewRow.Item("proptype") = ComboBox1.Text
dsNewRow.Item("pertype") = ComboBox2.Text
dsNewRow.Item("rooms") = ComboBox3.Text
dsNewRow.Item("invesadd") = TextBox9.Text
dsNewRow.Item("ivestsub") = TextBox10.Text
dsNewRow.Item("investpost") = TextBox11.Text
ds.Tables("customer").Rows.Add(dsNewRow)
da.Update(ds, "customer")
MsgBox("Data Updated")
-
Re: update database
The issue is most likely that you have one or more column names that are reserved words. The obvious culprit is "max". Either change them or else you must escape them to force them to be interpreted as identifiers. To do that, set the QuotePrefix and QuoteSuffix properties of your command builder to "[" and "]" respectively.
-
Re: update database
Thank you, I thought that may be the case but didnt think any were reserved.
All working now thanx again