newbie - what should the sql in my insert command look like?

J

Jim Lawton

I've puzzled over my c# book and examples on the web, but i cannot see what the
logic of this is. Sorry this is such a gash bit of code, but the question is, I
have inserted a row in to the dataset. Now I want to get that update applied to
the actual table, but I don't want to parameterise the data or anything like
that, cos I've already inserted it. All I want is the row I created in the real
table.

Similar problems will apply to amended rows - lets say I select certain rows,
update them all in the dataset, then want to write them *all* back. No
parameters no selection.

TIA, Jim


OdbcConnection con = new OdbcConnection("DRIVER={MySQL ODBC 3.51
Driver};Server=localhost;Database=mySQL;Uid=***;Pwd=**;option=3");

OdbcCommand selcmd = new OdbcCommand("SELECT * FROM TEST1", con);
OdbcCommand inscmd=newOdbcCommand(????????????????????????);

OdbcDataAdapter da = new OdbcDataAdapter(selcmd);
da.InsertCommand = inscmd;

DataSet ds = new DataSet();
da.Fill(ds,"TEST1");

DataRow row = ds.Tables[0].NewRow();
row[0] = "newdeal";

ds.Tables[0].Rows.Add(row);

da.Update(ds,"TEST1");
 
J

Jim Lawton

I've puzzled over my c# book and examples on the web, but i cannot see what the
logic of this is. Sorry this is such a gash bit of code, but the question is, I
have inserted a row in to the dataset. Now I want to get that update applied to
the actual table, but I don't want to parameterise the data or anything like
that, cos I've already inserted it. All I want is the row I created in the real
table.

Similar problems will apply to amended rows - lets say I select certain rows,
update them all in the dataset, then want to write them *all* back. No
parameters no selection.

TIA, Jim

OK - I found it ... for those who follow, solution below
OdbcConnection con = new OdbcConnection("DRIVER={MySQL ODBC 3.51
Driver};Server=localhost;Database=mySQL;Uid=***;Pwd=**;option=3");

OdbcCommand selcmd = new OdbcCommand("SELECT * FROM TEST1", con);
OdbcCommand inscmd=newOdbcCommand(????????????????????????);

OdbcDataAdapter da = new OdbcDataAdapter(selcmd);
da.InsertCommand = inscmd;

DataSet ds = new DataSet();
da.Fill(ds,"TEST1");

DataRow row = ds.Tables[0].NewRow();
row[0] = "newdeal";

ds.Tables[0].Rows.Add(row);

da.Update(ds,"TEST1");

I needed to create a CommandBuilder for my DataAdapter :-
this code works ..

OdbcDataAdapter da = new OdbcDataAdapter(cmd);
OdbcCommandBuilder builder = new OdbcCommandBuilder(da);



DataSet ds = new DataSet();
da.Fill(ds);

DataRow row = ds.Tables[0].NewRow();
row[0] = "newdeal";
ds.Tables[0].Rows.Add(row);

da.Update(ds);

cheers Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top