ADO.NET Question

ADO.NET Question

am 27.12.2007 16:35:02 von Rohit

I have a function here which takes a dataset as an argument and attempts to
update a SQL CE table with the data in the dataset. However it is not
working. When I check the database, there are no records in the table. Can
somebody help? Here is the code:

public void sync_db(DataSet d, string table_name, bool open)
{
if (open) con.Open();
SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM " +
table_name, con);
SqlCeCommandBuilder cmdb = new SqlCeCommandBuilder(da);
da.InsertCommand = cmdb.GetInsertCommand();
da.DeleteCommand = cmdb.GetDeleteCommand();
da.UpdateCommand = cmdb.GetUpdateCommand();
da.Update(d);
if (open) con.Close();
}

Re: ADO.NET Question

am 27.12.2007 16:51:26 von notmyfirstname

Rohit,

A DBDataAdapter updates data in datasets, datatables or datarows as long as
the rows in those have rowstates that are changed, inserted or updated.

As long as that is not the case, nothing is done.

(The setting of the Delete command from the commandbuilder is without sense,
that is not the way the commandbuilder is working, you can leave that it has
no effect).

Cor

Re: ADO.NET Question

am 27.12.2007 17:48:01 von Rohit

Thanks.

I got it to work by using a DataTableReader and writing an explicit loop to
iterate through the reader and explicitly insert the rows into the SQL CE
database.

Is there a way to take a given dataset and populate a database table with
the data in the dataset without writing an explicit loop in C#? Also, I want
the function sync_db to be generic so that it can be used for a variety of
different database tables.

"Cor Ligthert[MVP]" wrote:

> Rohit,
>
> A DBDataAdapter updates data in datasets, datatables or datarows as long as
> the rows in those have rowstates that are changed, inserted or updated.
>
> As long as that is not the case, nothing is done.
>
> (The setting of the Delete command from the commandbuilder is without sense,
> that is not the way the commandbuilder is working, you can leave that it has
> no effect).
>
> Cor
>

Re: ADO.NET Question

am 27.12.2007 22:06:51 von notmyfirstname

Rohit,

Have a look at the fill, there is an property to set the rows changed while
it is filled.

http://msdn2.microsoft.com/en-us/library/system.data.common. dataadapter.acceptchangesduringfill(VS.71).aspx

I never understood why people wanted that DataTableReader by the way, while
the Fill is so efficient.

Cor

"