Friday, July 4, 2008

Creating DataTable manually [C# VS2005]

We can create our own DataTable, named the column and fill the rows manually without accessing the database
DataTable dtCustomer = new DataTable();
dtCustomer.Columns.Add("Name");
dtCustomer.Columns.Add("Address");

DataRow dr = dtCustomer.NewRow();
dr["Name"] = "silenr0c";
dr["Address"] = "Bugis Street";
dtCustomer.Rows.Add(dr);

dr = dtCustomer.NewRow();
dr["Name"]= "Matsumoto";
dr["Address"] = "Tokyo";
dtCustomer.Rows.Add(dr);

DataView dv = new DataView( dtCustomer);

No comments: