Hello peeps. I hope this in the right place as its a vb.net question relating to databases :P
I am new to ADO.net and no matter how many resources I try to use on the web I cant get my head around how to add records. I thought I had it sussed with the following code but it just wont add a record
The following code is trying to add a records to the Administrators table using the OLEDBCommandBuilder and oleDBDataAdapter objects, it all goes well until it hits the 'DataConnector.update' line where it throws a wobbly saying
"Syntax error in INSERT INTO statement"
Have I got the wrong end of the stick entirely with this stuff?![]()
Any help or advice would be most welcome![]()
Code:Dim DB As New OleDbConnection Dim Command As New OleDbCommand Dim DataConnector As New OleDbDataAdapter Dim Records As New DataSet Dim Builder As OleDbCommandBuilder Dim RecordsRow As DataRow 'Open the database DB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & System.AppDomain.CurrentDomain.BaseDirectory & "AdminServerSettings\Administrators.mdb" DB.Open() 'Recordset information Command.Connection = DB Command.CommandText = "SELECT * FROM [Administrators] WHERE [ID] = " & ID 'Set to the data connector Dataconnector.SelectCommand = Command 'Allow changes to occur Builder = New OleDbCommandBuilder(DataConnector) 'Populate the recordset DataConnector.Fill(Records, "ADMINS") 'ADD RecordsRow = Records.Tables("ADMINS").NewRow() 'Store details RecordsRow("name") = Name RecordsRow("Information") = Information RecordsRow("Address") = Address RecordsRow("Email") = Email RecordsRow("Company") = Company RecordsRow("PostCode") = PostCode RecordsRow("Town") = Town RecordsRow("Telephone") = Telephone RecordsRow("Password") = Password RecordsRow("Username") = UserName RecordsRow("Status") = Status 'Add Records.Tables("ADMINS").Rows.Add(RecordsRow) 'Update DataConnector.Update(Records, "ADMINS")





Reply With Quote