DataGridView is not showing data: DataSet is empty
I created one project and I was using L2S. So it works fine.
So after I use the same connection string and create a new WinForm project. I put the datagrid by selecting this connection string. I am selecting DataMember and row headers. But when I run the application I look at the locals and I see the DataSet has all tables empty. I assumed they would be auto-populated from the DB, but they don't. So what should I do? DB is not empty.
PS I actually searched Google.
So it doesn't really fill in automatically. I have a Benefits table. So I typed
private void Form1_Load(object sender, EventArgs e)
{
RadikDataSet.BenefitsDataTable benefitsDataTable = new BenefitsTableAdapter().GetData();
dataGridView1.DataSource = benefitsDataTable;
}
and it works. So tnx. It's so stupid that I have to call it manually.
0
source to share
2 answers
Are you using a BindingSource? Make sure you assign it in the upload form like so:
private void Form1_Load(object sender, System.EventArgs e)
{
// Bind the DataGridView to the BindingSource
// and load the data from the database.
dataGridView1.DataSource = bindingSource1;
GetData("select * from Alex_db");
}
A more detailed example is available here.
+1
source to share