Recent News

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!!

SQL connection string

Hi All,

 we are all know how to connect the SQL Database from our C#. I am just given the syntax of Connection String which is used to connect the SQL.

connectionstring = "Data Source=DBName;Initial Catalog=Test;User Id=sa;Password=123;"



Thanks,
Sarav





Followers

Top Commentators

Recent Comments | Recent Posts


bottom