//Web.Config File Connection String
add name="Master1" connectionString ="Data Source=.;user id=; password=; database=Master; "/>
//aspx.cs
//Bind Function and call that function where you want..
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Master1"].ConnectionString);
private void bindData()
{
DataSet ds;
SqlDataAdapter da;
string sql = null;
ds = new DataSet();
da = new SqlDataAdapter();
try
{
con.Open();
}
catch (Exception ex)
{
}
sql = "Select student_id,last_name,first_name,Score from Student ;
da.SelectCommand = new SqlCommand(sql, con);
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = ds;
GridView1.DataBind();
if (ds.Tables.Count == 0)
{
//lblMessage.Text = "No record found";
}
}
ds = null;
da = null;
try { con.Close(); }
catch (Exception ex) { }
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment