//create function for data list binding
//reference http://www.bhukkad.com
private void TopTen_GurgaonRest(){
try
{
SqlCon.Open();
// add store procedure and call sql connection string
SqlCmd =
new SqlCommand(“proc_ten_GurgaonRest”, SqlCon);//define command type store procedure or direct sql query
SqlCmd.CommandType =
CommandType.StoredProcedure;
//create sql data adapter
SqlDataAdapter Sqlda = new SqlDataAdapter(SqlCmd);
// create data set for store data in data set
DataSet Ds = new DataSet();Sqlda.Fill(Ds);
// data list bound control using data set
DataList_Top_Gurgaon.DataSource = Ds;
DataList_Top_Gurgaon.DataBind();
}
catch (Exception
ex){
// if data list bind failed then throws exception
Response.Write(ex.ToString());
}
// connection close when data list will be bound
finally
{
SqlCon.Close();
}
}
Filed under: asp.net Tagged: | asp.net, bound datalist control, c#, sql data command, sql server, using storeprocedure