Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Does not fill the datagridview with this datatable, where is the problem?




private void button1_Click(object sender, EventArgs e)
{
llenarDataSet();
}



public static DataSet llenarDataSet()
{

DataTable dataT = new DataTable();
dataT.Columns.Add("numeroactivo");
dataT.Columns.Add("serieactivo");


DataRow datarow;
datarow = dataT.NewRow();
datarow["numeroactivo"] = "0001";
datarow["serieactivo"] = "339434111";
///Anadimos esta fila
dataT.Rows.Add(datarow);


datarow = dataT.NewRow();
datarow["numeroactivo"] = "0002";
datarow["serieactivo"] = "999991111";
///Anadimos esta fila
dataT.Rows.Add(datarow);

DataSet1 ds = new DataSet1();
ds.Tables.Add(dataT);



return ds;

}

private void button2_Click(object sender, EventArgs e)
{
DataSet1 ds = new DataSet1();
dataGridView1.DataSource = ds.Tables[0];

}
Posted
Comments
[no name] 3-May-14 20:51pm    
private void button2_Click(object sender, EventArgs e)
{
DataSet1 ds = new DataSet1();
dataGridView1.DataSource = ds.Tables[0];
}
Because you are creating a brand new empty dataset and setting that as your data source.
DamithSL 3-May-14 21:04pm    
Repost, please delete this question, you already ask the same http://www.codeproject.com/Questions/768405/Fill-datagridview-with-a-datatable-of-dataset
Animesh Datta 5-May-14 3:00am    
first of all declare the DataSet1 globally ,so that once you load the DataSet1 it remains unchanged and set it as a DataSource of Datagridview .

1 solution

Hello
plz do this

Declare dataset1 out side of both function....it's just a Scop problem
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900