Site Meter Asp.Net-Csharp,Asp,Ado.Net,Ado,Micosoft,Visualstudio,Visual webgui: Datarow
Showing posts with label Datarow. Show all posts
Showing posts with label Datarow. Show all posts

Friday, December 11, 2009

Overview and example for Datatable in asp.net

Overview and example for Datatable in asp.net:


MEthod 1:


DataTable cTable = new DataTable();
DataRow d3;

cTable.Columns.Add("A", typeof(string));
cTable.Columns.Add("B", typeof(string));
cTable.Columns.Add("C", typeof(string));

d3 = cTable.NewRow();
d3[0] = "A:";
d3[1] = B;
d3[2] = "C";

cTable.Rows.Add(d3);


Method 2:

DataTable dtProducts = new DataTable();
DataColumn productColumn = new DataColumn();

productColumn.DataType = System.Type.GetType("System.Int32");
productColumn.ColumnName = "id";
productColumn.Unique = true;
dtProducts.Columns.Add(productColumn);


DataTable dtProducts = createProductDT();

DataRow aProduct = dtProducts.NewRow();

aProduct["id"] = 11;
aProduct["thumb"] = "images/widget0.jpg";
aProduct["name"] = "Red Widget";
aProduct["price"] = 19.99;
dtProducts.Rows.Add(aProduct);