I have been working on a form that reads records from a SQL database. I have the binding working in that it populates all of the fields with the correct data. But if I am viewing record 1 and record 2 changes while I'm looking at 1, then browse to record 2, it shows me the old data unless I close and re-open the form which causes the binding to happen over again with the new data.

Is there a way to have the data in the dataset updated with each record change?

Here is the relevant form code...any suggestions would be greatly appreciated:

public partial class EditorAccounts : Form
        #region Globals

        BindingSource bindsrc;


        public EditorAccounts()

        #region On Load Events

        private void EditorAccounts_Load(object sender, EventArgs e)

            #region Error Handlers

            Messages errors = new Messages();


            #region Connect to Database

            //get default server type
            string ServerType = Properties.Settings.Default.SQLType.ToString();

            //get our connection string
            ConnectionManager ConnectionString = new ConnectionManager();
            string SQLConnectionString = ConnectionString.ConnectionString(ServerType);
            SqlConnection Connection = new SqlConnection();
            Connection.ConnectionString = SQLConnectionString;

            //try opening the connection
                //connection failed
                //give error message


            #region Retrieve Data

                SqlCommand query = new SqlCommand("SELECT * FROM accounts", Connection);
                SqlDataAdapter adrQuery = new SqlDataAdapter(query);
                DataSet dsQuery = new DataSet();
                adrQuery.Fill(dsQuery, "accounts");

                bindsrc = new BindingSource(dsQuery, "accounts");

                DataNavigator.BindingSource = bindsrc;

                #region Bindings

                //bind our data to the fields
                //I cut this out of my post because it was forever and a day long.


            catch (Exception x)



Edited by zachattack05: n/a

8 Years
Discussion Span
Last Post by zachattack05

I think I figured out what I need to do, but....I'm not quite sure how to do it?

I think i need to call adrQuery.Fill(dsQuery, "accounts") again, but since that dataset that needs to be filled again is located in the on_load portion of the form, I can't call it again without recreating the entire data adapter etc... and that just seems like a bad idea?

Any suggestions?

Edited by zachattack05: n/a


I figured it out.

I placed:
SqlCommand query;
SqlDataAdapter adrQuery;
DataSet dsQuery;
in globals and then just called:

int recordCurrent = int.Parse(DataNavigatorPositionItem.Text) - 1;
            adrQuery.Fill(dsQuery, "accounts");
            bindsrc.Position = recordCurrent;

in any event that I need the recordset to update and it works!

Just in case anyone else had the same problem :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.