using System.Data;
using System.Configuration;
using System.Data.SqlClient;
protected void Page_Load(object sender, EventArgs e) {
datareaderuse();
}
protected void datareaderuse() {
using(SqlConnection con = new SqlConnection("Data Source=LAPTOP6\\MSSQLSERVER2014;Initial Catalog=SEPTNEW;Integrated Security=True;")) {
using(SqlCommand cmd = new SqlCommand("Select * from City_Master")) {
cmd.Connection = con;
con.Open();
using(SqlDataReader sdr = cmd.ExecuteReader()) {
//Create a new DataSet.
DataSet dsCustomers = new DataSet();
dsCustomers.Tables.Add("City_Master");
//Load DataReader into the DataTable.
dsCustomers.Tables[0].Load(sdr);
GridView1.DataSource = dsCustomers.Tables[0];
GridView1.DataBind();
}
}
}
}This code snippet is for to load DataSet from SqlDataReader and fill GridView.
