0
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();
Habib
  • 219,104
  • 29
  • 407
  • 436
odlan yer
  • 721
  • 1
  • 7
  • 15

3 Answers3

2

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;
Community
  • 1
  • 1
Habib
  • 219,104
  • 29
  • 407
  • 436
1

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;
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
0

You are disposing your dataset right after you have added it to your grid

JohnnBlade
  • 4,261
  • 1
  • 21
  • 22