what is wring with this code?

  • Thread starter Thread starter Guest
  • Start date Start date
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;
}
}
 
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.
 
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;
}
}
 
Back
Top