No updating the table

S

sweetpotatop

Hi,

I am using the following to update some rows in a dataset, I wonder
why the data is no updated in the SQL table. Am I missing anything?
Please advice, your help would be greatly appreciated.

commandTimeoutPeriod = 120;
typeCommand = CommandType.Text;
command.CommandText = commandExecution;
command.Connection = connection;
command.CommandTimeout = commandTimeoutPeriod;
command.CommandType = typeCommand;
SqlDataAdapter adapter = null;

// initialize the adapter and dataset
adapter = new SqlDataAdapter(command);
if( ds == null) ds = new DataSet();
adapter.Fill(ds);

TestData = ds.Tables[ 0 ];

foreach(DataRow record in TestData.Rows)
{
row["field"] = YES_FLAG;
}
 
G

Guest

sweetpotatop,

You are not showing any code to update the database.

One method would be to call the dataadapter's Update method, sending it the
dataset/datatable as a parameter.

Ofcourse, the dataadapter will need to be supplied with valid Insert, Update
and Delete commands.

Kerry Moorman
 
S

sweetpotatop

sweetpotatop,

You are not showing any code to update the database.

One method would be to call the dataadapter's Update method, sending it the
dataset/datatable as a parameter.

Ofcourse, the dataadapter will need to be supplied with valid Insert, Update
and Delete commands.

Kerry Moorman



I am using the following to update some rows in a dataset, I wonder
why the data isnoupdatedin the SQL table. Am I missing anything?
Please advice, your help would be greatly appreciated.
commandTimeoutPeriod = 120;
typeCommand = CommandType.Text;
command.CommandText = commandExecution;
command.Connection = connection;
command.CommandTimeout = commandTimeoutPeriod;
command.CommandType = typeCommand;
SqlDataAdapter adapter = null;
// initialize the adapter and dataset
adapter = new SqlDataAdapter(command);
if( ds == null) ds = new DataSet();
adapter.Fill(ds);
TestData = ds.Tables[ 0 ];
foreach(DataRow record in TestData.Rows)
{
row["field"] = YES_FLAG;
}- Hide quoted text -

- Show quoted text -

I have been trying to use
adapter.update(ds, "mytable") however, I got an error
"Update requires a valid UpdateCommand when passed DataRow collection
with modified rows"

The think is I can't use the update command, I would like to do
something like this, is it possible?

foreach(DataRow record in TestData.Rows)
{
row["field"] = YES_FLAG;
}
update(ds, "mytable")
 
S

sweetpotatop

sweetpotatop,
You are not showing any code to update the database.
One method would be to call the dataadapter's Update method, sending it the
dataset/datatable as a parameter.
Ofcourse, the dataadapter will need to be supplied with valid Insert, Update
and Delete commands.
Kerry Moorman
Hi,
I am using the following to update some rows in a dataset, I wonder
why the data isnoupdatedin the SQL table. Am I missing anything?
Please advice, your help would be greatly appreciated.
commandTimeoutPeriod = 120;
typeCommand = CommandType.Text;
command.CommandText = commandExecution;
command.Connection = connection;
command.CommandTimeout = commandTimeoutPeriod;
command.CommandType = typeCommand;
SqlDataAdapter adapter = null;
// initialize the adapter and dataset
adapter = new SqlDataAdapter(command);
if( ds == null) ds = new DataSet();
adapter.Fill(ds);
TestData = ds.Tables[ 0 ];
foreach(DataRow record in TestData.Rows)
{
row["field"] = YES_FLAG;
}- Hide quoted text -
- Show quoted text -

I have been trying to use
adapter.update(ds, "mytable") however, I got an error
"Update requires a valid UpdateCommand when passed DataRow collection
with modified rows"

The think is I can't use the update command, I would like to do
something like this, is it possible?

foreach(DataRow record in TestData.Rows)
{
row["field"] = YES_FLAG;
}
update(ds, "mytable")- Hide quoted text -

- Show quoted text -


Since I will be updating different field values of a datarow from
different part of the source, code, I wonder if I can do this without
using the "UPDATE table SET field = value" . I hope I would wrap up
the update by simply using update(ds, "mytable"), I remember I can do
this in my past project, just wondering why I can't do it now.

Thanks
 

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