Example : How to store multiple records into datagrid view of Asp.net/C# from Sql Server Database.
protected void Page_Load(object sender, EventArgs e)
{
string cs = "data source =.; database= SITEDB; integrated security=SSPI";
//string cs = @"Data Source =.; Initial Catalog=SITEDB;";
con = new SqlConnection(cs);
Response.Write("Data Base Connected...");
try
{
con.Open();
SqlCommand cmd = new SqlCommand("select Slno, Name as [Customer Name], Email+', '+Pass as [Mail & Password], Dob as [Date of Birth], Gen as Gender, Matric+', '+ Inter+', '+ Grad+', '+PGrad as Qulification, Address+','+city+','+pin as Address from Traildb", con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows == true)
{
GridView1.DataSource = dr;
GridView1.DataBind();
}
}
catch (SqlException ex)
{
Response.Write(ex.Message);
}
finally
{
con.Close();
}
}
Example : How to store multiple records into datagrid view from html controls or text boxes in Asp.net/C#.
0 Comments