Sample function to load a normal asp.net gridview using sql
protected void LoadGridViewUsingSQL()
{
string connStr = "server= local);database=Northwind;uid=userid;pwd=password";
SqlConnection sqlConn ;
SqlCommand cmd = new SqlCommand();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
cmd.CommandText = "Ten Most Expensive Products";
cmd.CommandType = CommandType.StoredProcedure;
using (sqlConn = new SqlConnection(connStr))
{
cmd.Connection = sqlConn;
da.Fill(ds);
}
GridView1.DataSource = ds;
GridView1.DataBind();
}
No comments:
Post a Comment