Here I am going to write a C# Function in web form & a stored procedure for selecting data from table and display that in Grdiview.
create procedure sp_name
as
begin
select * from User_Details;
end
void GetData_proc()
{
con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);
cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "sp_name";
cmd.Connection = con;
try
{
con.Open();
GridView1.DataSource = cmd.ExecuteReader();
GridView1.DataBind();
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
con.Dispose();
}
}