odlan yer
odlan yer

Reputation: 771

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();

Upvotes: 0

Views: 337

Answers (3)

Habib
Habib

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

KV Prajapati
KV Prajapati

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

JohnnBlade
JohnnBlade

Reputation: 4327

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

Upvotes: 0

Related Questions