在代码后面调用两个程序。(加载事件)..对于下面提到的问题.... [英] call two procedure in code behind file.(load event)..for below mention problem....

查看:60
本文介绍了在代码后面调用两个程序。(加载事件)..对于下面提到的问题....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Adde 你可以在(page_load事件)中的代码隐藏文件中调用两个存储过程。



网格视图和datalist那里是两个控件使用,,,,你怎么能调用两个程序???



折叠|复制代码

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

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();
    }
}





这是针对datalist的......你怎么能为gridview调用存储过程.. ..



this is for datalist ...how can u call store procedure for gridview....

推荐答案

hi



如果您将相同的数据绑定到两者然后将reader对象绑定到gridview也。否则创建新命令和datareader对象并绑定它。
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.


你好,



这取决于,如果你想这样做来自代码的单个调用。然后编写一个包装器存储过程并从包装程序调用这些过程。否则,您可以创建两个命令对象实例来调用两个单独的proc并一个接一个地调用它们。您始终可以使用事务管理来确保数据的良好性。见[ ^ ]



问候,
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,


这篇关于在代码后面调用两个程序。(加载事件)..对于下面提到的问题....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆