I have added a sdf
file to my project then created a table and inserted a few data then I wrote this code below. But when I run project datagridview looks empty. I have checked that sdf
file exists.
private void Form1_Load(object sender, EventArgs e)
{
con = new SqlConnection(@"Data Source=c:\users\xxx\documents\visual studio 2012\Projects\WindowsFormsApplication6\WindowsFormsApplication6\Database1.sdf");
adp = new SqlDataAdapter("select * from info", con);
adp.Fill(dt);
dataGridView1.DataSource = dt;
}
You can check if the table has records using the following sequence:
cm = new sqlcommand("select count(field_name) from info", con)
iRecords = cm.executescalar
msgbox(iRecords)
Try to debug and see if you are really getting the data into the DataTable "dt" .
Check the property for "AutoGenerateColumns" is set to true .
By default "AutoGenerateColumns" is true ,
Still there are chances of overriding.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.