Loading data from the reader to data table

Posted by Nishithraj under ASP.NET category on | Views : 2094
If there is a situation to load all the data of a data reader to a data table, you can use the following code.
Here the load function of the data table will load all the data to the data table.

string ConStr= 'Declare the connection string here';
objCon= new SqlConnection(ConStr);
SqlCommand cmd = new SqlCommand('Some Query', objCon);
SqlDataReader objRead = cmd.ExecuteReader(CommandBehavior.CloseConnection);
DataTable objDt = new DataTable();
objDt.Load(objRead );

Comments or Responses

Login to post response