简体   繁体   中英

No data appear on my datagridview when using dataset in c#, what am i missing here?

SqlCommand cmd = new SqlCommand("Select sur_accounttype from tsys_user",conSQL ) ;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds,"tsys_user");
dataGridView1.DataSource = ds;
ds.Dispose();

Remove this from your code

ds.Dispose();

ds.Dispose actually doesn't do anything . The problem is with specifying the datasource to a table in the dataset.

dataGridView1.DataSource = ds.Tables[0].DefaultView;

Try to set DataMember property.

dataGridView1.DataSource = ds;
dataGridView1.DataMember="tsys_user";

Or create a DataTable and populate it.

DataTable dt=new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;

将数据集添加到网格中后,便要对其进行处置

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM