views:

29

answers:

2

Hello,

I have a datagridview that is bound to a dataset

I defined the table and the columns, how I can programmaticlly insert data to it?

I did this http://msdn.microsoft.com/en-us/library/5ycd1034%28VS.71%29.aspx

but it did not show the data in my DataGridView !!!

+1  A: 

now you need to assign the values to the datagridview

DataTable dt = new DataTable();

// Add rows to dt 
datagridview.DataSource = dt;
anishmarokey
but datagridview is already configured with dataset!, is it ok?
Data-Base
+1  A: 

Sample example

SqlDataAdapter da = new SqlDataAdapter(quryString, con);
DataSet ds = new DataSet();
da.Fill(ds, "Emp");

//dataGridView1.DataSource = ds.Tables["Emp"];
dataGridView1.Columns.Add("EmpID", "ID");
dataGridView1.Columns.Add("FirstName", "FirstName");
dataGridView1.Columns.Add("LastName", "LastName");
int row = ds.Tables["Emp"].Rows.Count - 1;

for (int r = 0; r<= row; r++)
{
dataGridView1.Rows.Add();
dataGridView1.Rows[r].Cells[0].Value = ds.Tables["Emp"].Rows[r].ItemArray[0];
dataGridView1.Rows[r].Cells[1].Value = ds.Tables["Emp"].Rows[r].ItemArray[1];
dataGridView1.Rows[r].Cells[2].Value = ds.Tables["Emp"].Rows[r].ItemArray[2];

}
Johnny