SqlCommandBuilder

G

Guest

Hi,
I am using a SqlCommandBuilder to update a Db table via an updated DataSet
and SqlAdapter and it doesn't seem to be generating the activity commands
from the Select command. Here is a snippet.

sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand(sql,dbcon);
SqlCommandBuilder scb = new SqlCommandBuilder(sda);

DataSet ds = new DataSet();
sda.Fill(ds,pageName);

DataRow dr = ds.Tables[pageName].NewRow();

for(int x=0;x<14;x++)
{
dr[x] = newDataRow[x];
}
ds.Tables[pageName].Rows.Add(dr);
ds.AcceptChanges();
sda.Update(ds,pageName);

Nothing happens, no update and no exceptions. Any ideas please?

Jim
 
M

Marina

Yes - you called AcceptChanges. This changes the states of all the rows to
unmodified. So when you go to update, it looks like there is nothing to
update.

Why call AcceptChanges to change all the row states if you then want to
update?
 
G

Guest

Doh!

Thanks very much Marina. Why would you need to call AcceptChanges on a
DataSet?

Jim

Marina said:
Yes - you called AcceptChanges. This changes the states of all the rows to
unmodified. So when you go to update, it looks like there is nothing to
update.

Why call AcceptChanges to change all the row states if you then want to
update?

Jim Reynolds said:
Hi,
I am using a SqlCommandBuilder to update a Db table via an updated DataSet
and SqlAdapter and it doesn't seem to be generating the activity commands
from the Select command. Here is a snippet.

sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand(sql,dbcon);
SqlCommandBuilder scb = new SqlCommandBuilder(sda);

DataSet ds = new DataSet();
sda.Fill(ds,pageName);

DataRow dr = ds.Tables[pageName].NewRow();

for(int x=0;x<14;x++)
{
dr[x] = newDataRow[x];
}
ds.Tables[pageName].Rows.Add(dr);
ds.AcceptChanges();
sda.Update(ds,pageName);

Nothing happens, no update and no exceptions. Any ideas please?

Jim
 
M

Marina

If you used GetChanges to get just the changes, and after the save was done,
you wanted to reset all the rows to unchanged, to match.

Or if you had application logic the required you for some reason to want
this to happen.

Jim Reynolds said:
Doh!

Thanks very much Marina. Why would you need to call AcceptChanges on a
DataSet?

Jim

Marina said:
Yes - you called AcceptChanges. This changes the states of all the rows
to
unmodified. So when you go to update, it looks like there is nothing to
update.

Why call AcceptChanges to change all the row states if you then want to
update?

Jim Reynolds said:
Hi,
I am using a SqlCommandBuilder to update a Db table via an updated
DataSet
and SqlAdapter and it doesn't seem to be generating the activity
commands
from the Select command. Here is a snippet.

sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand(sql,dbcon);
SqlCommandBuilder scb = new SqlCommandBuilder(sda);

DataSet ds = new DataSet();
sda.Fill(ds,pageName);

DataRow dr = ds.Tables[pageName].NewRow();

for(int x=0;x<14;x++)
{
dr[x] = newDataRow[x];
}
ds.Tables[pageName].Rows.Add(dr);
ds.AcceptChanges();
sda.Update(ds,pageName);

Nothing happens, no update and no exceptions. Any ideas please?

Jim
 
G

Guest

Thanks very much.

Marina said:
If you used GetChanges to get just the changes, and after the save was done,
you wanted to reset all the rows to unchanged, to match.

Or if you had application logic the required you for some reason to want
this to happen.

Jim Reynolds said:
Doh!

Thanks very much Marina. Why would you need to call AcceptChanges on a
DataSet?

Jim

Marina said:
Yes - you called AcceptChanges. This changes the states of all the rows
to
unmodified. So when you go to update, it looks like there is nothing to
update.

Why call AcceptChanges to change all the row states if you then want to
update?

Hi,
I am using a SqlCommandBuilder to update a Db table via an updated
DataSet
and SqlAdapter and it doesn't seem to be generating the activity
commands
from the Select command. Here is a snippet.

sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand(sql,dbcon);
SqlCommandBuilder scb = new SqlCommandBuilder(sda);

DataSet ds = new DataSet();
sda.Fill(ds,pageName);

DataRow dr = ds.Tables[pageName].NewRow();

for(int x=0;x<14;x++)
{
dr[x] = newDataRow[x];
}
ds.Tables[pageName].Rows.Add(dr);
ds.AcceptChanges();
sda.Update(ds,pageName);

Nothing happens, no update and no exceptions. Any ideas please?

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