本文介绍了如何使用STORED PROC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的WebForm中有一个dataGrid,我想使用
存储过程以填充DataGrid.

有人可以帮我吗. . .

非常感谢.

Hi All ,

i have one dataGrid in my WebForm and i want to use
a Stored Procedure to populate the DataGrid.

Can any one Help me please . . .

Many Thanks.

推荐答案


//retrieve Data .
using (
                  SqlConnection con =
                      new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
        {


            using (SqlCommand cmd = new SqlCommand("usp_test", con))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("tst", txt.Text);
                DataTable dt = new DataTable();
                SqlDataAdapter adpt = new SqlDataAdapter(cmd);
                adpt.Fill(dt);
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
        }


在ADO.NET中调用存储过程 [ ^ ]
http://www.csharp-station.com/Tutorial/AdoDotNet/lesson07 [ ^ ]
http://www.c-sharpcorner.com /UploadFile/718fc8/saving-record-using-stored-procedure-in-ado-net/ [ ^ ]
http://msdn.microsoft.com/en-us/library/59x02y99.aspx [ ^ ]
最好的问候
M.Mitwalli


Calling Stored procedures in ADO.NET[^]
http://www.csharp-station.com/Tutorial/AdoDotNet/lesson07[^]
http://www.c-sharpcorner.com/UploadFile/718fc8/saving-record-using-stored-procedure-in-ado-net/[^]
http://msdn.microsoft.com/en-us/library/59x02y99.aspx[^]
Best Regards
M.Mitwalli


SqlCommand cmd=new SqlCommand("spGetData", con);
//con is your connection object.
SqlDataAdapter sda=new SqlDataAdapte(cmd) ;
DataTable dt=new DataTable();
sda.Fill(dt);
con.Close();
DataGrid1.DataSource=dt;
DataGrid1.DataBind();



这会为您提供帮助.
祝一切顺利.

-AK



This will help you.
All the best.

-AK


这篇关于如何使用STORED PROC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 16:06