Articles → ADO.NET → Load datatable through datareader in

Load datatable through datareader in

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
			using(SqlCommand cmd = new SqlCommand("Select * from Course", oConnection)) {
				SqlDataReader dr = cmd.ExecuteReader();
				DataTable dt = new DataTable();


Click to Enlarge

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


Your Email Id  
Query/FeedbackCharacters remaining 250