Click here to Skip to main content
15,899,935 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
AddeCan u call the two store procedure inside the code behind file in(page_load event).

grid view and datalist there are two control used,,,,how can you call two procedure for that???

Collapse | Copy Code
C#
protected void Page_Load(object sender, EventArgs e)
{
    if (Page.IsPostBack == false)
    {
        SqlConnection objConn = new SqlConnection(ConfigurationManager.ConnectionStrings["BuildMyPCConnectionString"].ToString());
        objConn.Open();
 
        SqlCommand objCmd = objConn.CreateCommand();
        objCmd.CommandType = CommandType.StoredProcedure;
        objCmd.CommandText = "PR_ProductDetail_SelectByPK";
        objCmd.Parameters.AddWithValue("@ProductID", Convert.ToInt32(Request.QueryString["ProductID"]));
 
        SqlDataReader objSdr = objCmd.ExecuteReader();
 
        dlProductDetail.DataSource = objSdr;
        dlProductDetail.DataBind();
    }
}


this is for datalist ...how can u call store procedure for gridview....
Posted
Updated 28-Mar-13 1:34am
v2
Comments
[no name] 28-Mar-13 7:35am    
Why would you think you could not call another stored procedure? Of course you can.
[no name] 28-Mar-13 7:39am    
And of course had you read the answer to your other exact same question, you would have known that.

hi

if your binding same data to both then bind reader object to gridview also. else create new command and datareader object and bind it.
 
Share this answer
 
Hello,

It depends, if you want to do this in a single call from code behind. Then write a wrapper stored procedure and call these procedures from the wrapper procedure. Otherwise you can create two command object instances for calling two seperate procs and call them one after another. You can always use transaction management to ensure data intigrity. See [^]

Regards,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900