Articles → ADO.NET → Load datatable through datareader in

Load datatable through datareader in

Software requirement

Prerequisite knowledge

Steps of execution

Create a new table

Picture showing the design view of the table in sql server

Click to Enlarge

Add data in the table

Picture showing the table with data in sql server

Click to Enlarge

Create a new project

Picture showing the project structure of the sample project in solution explorer

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();


Picture showing the output of Load datatable through datareader in

Click to Enlarge

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


Your Email Id  
Query/FeedbackCharacters remaining 250