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;
#endregion
public EditorAccounts()
{
InitializeComponent();
}
#region On Load Events
private void EditorAccounts_Load(object sender, EventArgs e)
{
#region Error Handlers
Messages errors = new Messages();
#endregion
#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
try
{
Connection.Open();
Connection.Close();
}
catch
{
//connection failed
//give error message
errors.ErrorMessages(004);
}
#endregion
#region Retrieve Data
try
{
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.
#endregion
}
catch (Exception x)
{
MessageBox.Show(x.Message);
}
#endregion
}