Re: what is wring with this code?



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. wrote:
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;
}
}

.



Relevant Pages

  • drop down menu selected w/ source code
    ... I want my value from SQL database to be select in the drop down menu ... Also, once the user change to the value, update it back to database. ... SqlConnection sqlConn = new SqlConnection; ... DataTable dataTbl = new DataTable; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: copy data from one data set to another
    ... The DataSet is *not* connected to the Database, ... DataTable or DataTables *in* the DataSet. ... you append rows to the DataTable in one ... SqlConnection sqlConn = new SqlConnection; ...
    (microsoft.public.dotnet.framework.aspnet)
  • Retrieving Data from a Sybase Database
    ... I'm having difficulties retrieving some data from a sybase database ... Set sqlConn = CreateObject ... Any idea why the result cuts 'ShortNote' in the middle? ...
    (microsoft.public.inetsdk.programming.scripting.vbscript)
  • Re: Connection.GetSchema
    ... To check for a table in a sql server database use the sp_tables stored ... The following example iterates through all tables and uses a datareader ... If you need to first get a list of all databases on the server, ... sqlConn) ...
    (microsoft.public.dotnet.framework.adonet)
  • ADO.net update problem with VB and MS Access
    ... ADO.net to retrieve the information from the database. ... the update method in ADO.NET should be able to ... Private Sub SaveData() ... Protected Sub initalizeDataAdapter(ByVal cmdSel As OleDbCommand, ...
    (microsoft.public.dotnet.framework.adonet)