Reputation: 771
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();
Upvotes: 0
Views: 337
Reputation: 223372
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;
Upvotes: 2
Reputation: 94653
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;
Upvotes: 1
Reputation: 4327
You are disposing your dataset right after you have added it to your grid
Upvotes: 0