Create Data Table Dynamic
Hi All,
We can create a data table dynamically. That is we can get particular columns from the dataset where as the dataset having all columns/many columns. From that dataset we can get our necessary columns.
private DataTable GetInitalTable(DataSet ds)
{
//Instatiate the data table
DataTable dt = new DataTable();
//Initialise the column names
dt.Columns.Add("Id");
dt.Columns.Add("firstname");
//loop
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
//Assign/Adding the Rows from dataset
dt.Rows.Add(ds.Tables[0].Rows[i]["Id"], ds.Tables[0].Rows[i]["firstname"]);
}
// Return the data table!
return dt;
}
The input is the whole dataset records. But the we can get out put only with two columns as per the above example...
Happy Coding!!!!!!!
No Pain!... No Gain!!
Labels: cteate table, Dataset, datatable 0 Comments
Recent Comments