Error on updating database

error on using dataAdapter.update command

Page 1 of 1

2 Replies - 1006 Views - Last Post: 21 January 2010 - 12:52 AM Rate Topic: -----

#1 dfan23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 17-March 09

Error on updating database

Post icon  Posted 20 January 2010 - 10:27 AM

hello,
I would like to know if how can I update my database using oledbCommandBuilder
below here is my code:

'save changes made and store it to our database
		newDataRow = ds.Tables("employeeTable").NewRow()
		newDataRow.Item(0) = comboPosition.Text
		newDataRow.Item(1) = txtLastName.Text
		newDataRow.Item(2) = txtFirstName.Text
		'navigateAddRecord(newDataRow, comboPosition, txtLastName, txtFirstName)
		ds.Tables("employeeTable").Rows.Add(newDataRow)
		da.SelectCommand = New OleDb.OleDbCommand("select * from employeeTable", con)
		
		Dim cb As New OleDb.OleDbCommandBuilder(da)
		da.Update(ds, "employeeTable")
		con.Close()
		Me.Hide()
		EmployeeRecordsForm.Show()




The error that I get is "Syntax error in INSERT INTO statement." It almost took me 1 day but I cant
configure how it still become error.
below here is the part where the error came from
da.Update(ds, "employeeTable")





Thanks in advance for help,
dfan23

Is This A Good Question/Topic? 0
  • +

Replies To: Error on updating database

#2 Broozzz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 30-January 08

Re: Error on updating database

Posted 20 January 2010 - 01:07 PM

I think the error start at the top, where you say the newrecord is a new record in the ds.
i believe you should try with dim newrow as row ?

Then set the details for the row, then add it with the update to the ds
Was This Post Helpful? 0
  • +
  • -

#3 dfan23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 17-March 09

Re: Error on updating database

Posted 21 January 2010 - 12:52 AM

View PostBroozzz, on 20 Jan, 2010 - 12:07 PM, said:

I think the error start at the top, where you say the newrecord is a new record in the ds.
i believe you should try with dim newrow as row ?

Then set the details for the row, then add it with the update to the ds



Sorry for lack of details of my program
I have a new datarow but still I still get the error.
I have tried putting this code to get rid of the error but now
the problem it does not yet update the database
below here is the code of my program that dont have error but doesnt update yet
	'declarations
	Dim con As New OleDb.OleDbConnection
	Dim da As New OleDb.OleDbDataAdapter
	Dim ds As New DataSet
	Dim sSQL As String
	Dim cb As New OleDb.OleDbCommandBuilder(da)
	Dim counter As Integer
	Dim newRow As DataRow

	'my code for update
		newRow = ds.Tables("employeeTable").NewRow()
		newRow.Item(0) = cboPosition.Text
		newRow.Item(1) = txtLastName.Text
		newRow.Item(2) = txtFirstName.Text
		ds.Tables("employeeTable").Rows.Add(newRow)
		ds.AcceptChanges()
		da.Update(ds, "employeeTable")
		MsgBox("Files Saved")
		con.Close()




here is my previous code with run time error "invalid insert command"

  'declarations
	Dim con As New OleDb.OleDbConnection
	Dim da As New OleDb.OleDbDataAdapter
	Dim ds As New DataSet
	Dim sSQL As String
	Dim cb As New OleDb.OleDbCommandBuilder(da)
	Dim counter As Integer
	Dim newRow As DataRow
			  'my code for updating the database
				newRow = ds.Tables("employeeTable").NewRow()
		newRow.Item(0) = cboPosition.Text
		newRow.Item(1) = txtLastName.Text
		newRow.Item(2) = txtFirstName.Text
		ds.Tables("employeeTable").Rows.Add(newRow)
	   
		da.Update(ds, "employeeTable")
		MsgBox("Files Saved")
		con.Close()



Really confuse how come it says its invallid command. All comments suggestion
are kindly appreciated.


Thanks in advance for help,
dfan23

This post has been edited by dfan23: 21 January 2010 - 12:53 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1