Click to See Complete Forum and Search --> : How to Update Database using DataSet


skid_myanmar
March 29th, 2006, 12:56 AM
Hi everyone,

I wanna update my database using DataSet...I don't wanna use Insert or Update Command...I wanna add some rows to DataTable and then Update the Database...how can i acheive this goal

skid

jayender.vs
March 29th, 2006, 01:05 AM
Hi everyone,
I wanna update my database using DataSet...I don't wanna use Insert or Update Command...I wanna add some rows to DataTable and then Update the Database...how can i acheive this goal
skidCheck this: update a database from a DataSet object (http://support.microsoft.com/kb/q301248/) and Update a SQL Server Database (http://support.microsoft.com/kb/q308055/)

skid_myanmar
March 29th, 2006, 02:30 AM
Thanks jayender

I use OleDbCommandBuilder to solve this problem...
I got this error


Syntax error in INSERT INTO statement.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.

Source Error:

Line 110: adapter.Update(ds,"invoice");


And when I view autogenerated Insert Command...i c like this

Insert Into table (field1, field2,...) Values(?,?,...)

so if i use CommandBuilder...do i need to replace "?" with something...

Skid

skid_myanmar
March 29th, 2006, 03:27 AM
Thanks yayender,

I tried to use OleDbCommandBuilder. But I failed when I called dataadapter.update(dataset,"table");....it shows the error "error in Insert into statement"...when I view that statement from Combuilder...it looks like this

Insert Into table(field1,...) Values(?,...)

do i need to change the "?" with actual data

Thanks
Skid

jayender.vs
March 29th, 2006, 03:39 AM
Try to print out the actual sql statement and run it in the query command.

jayender.vs
March 29th, 2006, 03:44 AM
I read ,Syntax errors normally come from the following

1) Having a database field with a reserved name (such as Name, Desc,
Password)
2) Trying to insert a text value into a numeric field

The latter one can happen if a person enters a comma or a dollar sign in the input field.

Shuja Ali
March 29th, 2006, 04:20 AM
If you are using ? then you need to add parameters to to the OleDBCommand object. Please post the code in which you are building your query.

skid_myanmar
March 29th, 2006, 04:26 AM
Thanks all,
my code is as follow

OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\inetpub\wwwroot\eticketing\pandaw1947_1.mdb;");
OleDbDataAdapter adapter = new OleDbDataAdapter("select * from test",con);
OleDbCommandBuilder combuilder = new OleDbCommandBuilder(adapter);
DataSet ds = new DataSet();
adapter.Fill(ds,"users");
DataRow row = ds.Tables["users"].NewRow();
row[0] = "abc";
row[1] = 24;
row[2] = "abc";
ds.Tables["users"].Rows.Add(row);
adapter.Update(ds,"users");
DataGrid1.DataSource = ds;
DataGrid1.DataBind();

And when I view Command Builder's Insert Command Text, I got following

INSERT INTO test( name , age , position ) VALUES ( ? , ? , ? )


Skid