Wednesday, January 16, 2008

Datatable Load option in Dotnet Framework 2.0

Definition

Using datatable.load you can load the sqldatareader value directly

Example


DataTable dt = new DataTable();
string connectionstring = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlConnection myconn = new SqlConnection(connectionstring);
SqlCommand mycomm = new SqlCommand("select * from FA_contactdetails", myconn);
myconn.Open();
SqlDataReader sqldataread = mycomm.ExecuteReader();
dt.Load(sqldataread);////
myconn.Close();
dggrid.DataSource = dt;
dggrid.DataBind();