Articles → ADO.NET → Load datatable through datareader in ado.net

Load datatable through datareader in ado.net






















Software requirement









Prerequisite knowledge















Steps of execution















Create a new table





Click to Enlarge


Add data in the table





Click to Enlarge


Create a new project





Click to Enlarge


Add code to load datatable though datareader




using System;
using System.Data.SqlClient;
using System.Data;
public partial class _Default: System.Web.UI.Page {
	protected void Page_Load(object sender, EventArgs e) {
		using(SqlConnection oConnection = new SqlConnection(@"connection_string")) { // Open a connection
			oConnection.Open();
			using(SqlCommand cmd = new SqlCommand("Select * from Course", oConnection)) {
				SqlDataReader dr = cmd.ExecuteReader();
				DataTable dt = new DataTable();
				dt.Load(dr);
			}
		}
	}
}



Output



Click to Enlarge

Posted By  -  Karan Gupta
 
Posted On  -  Thursday, April 11, 2013

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250