No updating the table

  • Thread starter Thread starter sweetpotatop
  • Start date Start date
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;
}
 
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
 
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")
 
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
 
Back
Top