I want to bind the DataGridView to a Table in my Database. I've found several topics about this, but I can't get it to work. Perhaps I'm missing something.
I'm building a "monitor" in which I want to see any Database changes of a specific table. So, after loading the data into a DataGridView, any change in that specific table should be propagate to the DataGridView.
Look what I've done:
SqlDataAdapter daTab;
DataTable dTable;
private void button1_Click(object sender, EventArgs e)
{
string s;
s = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\tempDB\Database1.mdf;Integrated Security=True";
SqlConnection conn= new SqlConnection(s);
conn.Open();
daTab = new SqlDataAdapter("Select * From tab", conn);
dTable = new DataTable();
daTab.Fill(dTable);
BindingSource bSource = new BindingSource();
bSource.DataSource = dTable;
dgv1.DataSource = bSource;
}
But it only updates the DataViewGrid when I run
daTab.Fill(dTable);
So I may have two options from here: 1) get it to work right (this is why I'm needing your help) or 2) put a timer and run daTab.Fill(dTable);
at some time interval. I am particullary looking after option 1). So, I'd appreciate any help given.