what is wring with this code?

G

Guest

Hello,
With the following I am merging two dataset and I see the result in the
datagrid but not in myTable.
Where might my problem be?

private void myMethod()
{
try
{

string strConn = ConfigurationSettings.AppSettings["connectionString"];
SqlConnection sqlConn = new SqlConnection(strConn);

SqlDataAdapter daRS = new SqlDataAdapter("SELECT * From myTable", sqlConn);
SqlCommandBuilder cbRS = new SqlCommandBuilder(daRS);
sqlConn.Open();
DataSet dsRS = new DataSet();
daRS.Fill(dsRS,"myTable");

PVS.myWS.Loader load = new PVS.myWS.Loader();
PVS.myWS.PVSTDS ds=load.getDataSet();

dsRS.Merge(ds,true);

dataGrid1.DataSource=dsRS;

daRS.Update(dsRS,"myTable");
sqlConn.Close();

catch (Exception ex)
{
throw ex;
}
}
 
G

Guest

You mean that the records added to the DataSet isn't added to the
database table when you call Update?

That is because the records that are merged in have the RowState set to
DataRowState.Unchanged, so the Update method ignores them.

I think that you have to add the DataRows to the DataTable (using the
Add method of the Rows property) to be able to add them to the database
table.
 
G

Guest

Thank you very much for the reply.
I am quite new and I was wondering you can give me a sample of the code how
to do that?


Göran Andersson said:
You mean that the records added to the DataSet isn't added to the
database table when you call Update?

That is because the records that are merged in have the RowState set to
DataRowState.Unchanged, so the Update method ignores them.

I think that you have to add the DataRows to the DataTable (using the
Add method of the Rows property) to be able to add them to the database
table.

JIM.H. said:
Hello,
With the following I am merging two dataset and I see the result in the
datagrid but not in myTable.
Where might my problem be?

private void myMethod()
{
try
{

string strConn = ConfigurationSettings.AppSettings["connectionString"];
SqlConnection sqlConn = new SqlConnection(strConn);

SqlDataAdapter daRS = new SqlDataAdapter("SELECT * From myTable", sqlConn);
SqlCommandBuilder cbRS = new SqlCommandBuilder(daRS);
sqlConn.Open();
DataSet dsRS = new DataSet();
daRS.Fill(dsRS,"myTable");

PVS.myWS.Loader load = new PVS.myWS.Loader();
PVS.myWS.PVSTDS ds=load.getDataSet();

dsRS.Merge(ds,true);

dataGrid1.DataSource=dsRS;

daRS.Update(dsRS,"myTable");
sqlConn.Close();

catch (Exception ex)
{
throw ex;
}
}
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top