Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 23rd, 2004, 02:54 PM
Authorized User
 
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default Updating disconnected datasets

How can I reconnect a disconnected dataset to it's original datasource and use the dataset's Update method to update the datasource? I can't seem to update the datasource from an aspx page once the oledbConnection object used to get the original data has been closed and disposed of. I can update the dataset, but not the datasouce.

Jarrod
 
Old July 23rd, 2004, 03:31 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

You need to use the SQLDataAdapter to do the update. You will also need to reestablish and open the connection to the database when you do SQLDataAdapter.Update.

Do you use stored procedures or SQL queries to do the update?

Brian
 
Old July 24th, 2004, 12:59 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

you told you can update your dataset but not your datasource it's because of that you don't send your sql queries(like Update,Insert,...) to your datasource when you just use Update method through your Adapter.
in this case you should use a CommandBuilder(SqlCommandBuilder,OlDbBuilder,....) to make it send your queries to your datasource for affecting it
ofcourse another way could be building yor commands within your Adapter and then use update method in your Adapter
but easiest way is using CommandBuilder(just in one table)....
(just create one CommandBuilder and then update your adapter)
Hope this helps you...

--------------------------------------------
Mehdi
I'm waiting for your better idea.
 
Old July 24th, 2004, 01:15 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

Sure it'll be helpful for u http://msdn.microsoft.com/library/en...terdataset.asp

Always:),
Hovik Melkomian.
 
Old July 26th, 2004, 07:54 AM
Authorized User
 
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm still not getting my data source to update. Here is my sample code. Is it neccessary to refill the DataSet?

protected void doUpdate(object o, DataGridCommandEventArgs e)
{
    OleDbConnection conn = new OleDbConnection();
    try
    {
        // Code to get updated values from DataGrid
        // Fetch the cached DataSet from the Session object
        DataSet ds = getDataSet();
        // Code to update the appropriate DataRow
        ds.AcceptChanges();

        DataView dv = ds.Tables[0].DefaultView;
        DataGrid1.EditItemIndex = -1;

        // Reconnect to the database and Open
        conn.ConnectionString = connString;
        conn.Open();
        // Make a new OleDbDataAdapter
        OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM GAI_FN_SPEC_CLAIMS", conn);
        // Make a new OleDbCommandBuilder
        OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
        // Do the update and rebind the DataSet to the DataGrid
        da.Update(ds);
        DataGrid1.DataSource = dv;
        DataGrid1.DataBind();
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message);
    }
    finally
    {
        if (conn.State == ConnectionState.Open)
            conn.Close();
    }
}
 
Old July 26th, 2004, 09:48 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

You can't execute AcceptChanges before the update. AcceptChanges makes the RowState back to Unchanged (which the added rows should be Added RowState value and the updated rows should be Modified RowState value).

The Update statement should call AcceptChanges for you

Brian
 
Old July 26th, 2004, 09:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Also, just saw something, try getting the data view after you call the update statement, so you have the most accurate version. If you have an identity, the right value won't be sent back to the dataset until you call the update statement, and any other database changes such as from a trigger, default, etc.

Brian
 
Old July 26th, 2004, 10:37 AM
Authorized User
 
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Many thanks. AcceptChanges was killing me.

Jarrod





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dcount with local disconnected recordset DreamEagl Access VBA 7 March 10th, 2006 01:44 PM
Report from disconnected recordset DreamEagl Access VBA 4 January 9th, 2006 04:26 PM
Disconnected data architecture kumar_raj13 ADO.NET 1 December 6th, 2005 12:00 AM
The object invoked has disconnected from its clien Ciarano Beginning VB 6 2 March 12th, 2004 11:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.