在使用参数化存储过程填充gridview时遇到问题。 [英] Having problem filling the gridview with parameterized stored procedure.
本文介绍了在使用参数化存储过程填充gridview时遇到问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我根据给定的参数填写网格视图有问题。
我制作的存储过程如下:
I have a problem to fill a grid view according to the given parameter.
The stored procedure that I made is as following:
CREATE PROCEDURE [dbo].[procNAME]
(
@ID_Personi int
)
AS
BEGIN
SELECT SHKOLLA.ID_Shkolla, SHKOLLA.ShkollaEmertimi, SHKOLLA.VitiAkademik, SHKOLLA.ID_Personi, SHKOLLA.ID_Komuna
, LLOJI_SHKOLLES.LlojiShkolles FROM SHKOLLA
inner join LLOJI_SHKOLLES on LLOJI_SHKOLLES.ID_Shkolla=SHKOLLA.ID_Shkolla
where SHKOLLA.ID_Personi = @ID_Personi
END
我的问题是:如何发送此参数从网格视图填充到数据库。我用存储过程填充网格视图。
我需要一个c#代码。
P.S.此ID_Personi在页面加载时作为会话存在。
提前感谢您的回复。
My problem is: how to send this parameter to database from grid view population. I populate the grid view with stored procedure.
I need a c# code.
P.S. This ID_Personi exists as a Session on a page load.
Thank you in advance for your reply.
推荐答案
As RyanDev [ ^ ]在问题评论中提到,地球村 [ ^ ]充满了例子')
演练:使用SqlDataSource Web服务器控件调用存储过程 [ ^ ]
如何:Ex执行返回行的存储过程 [ ^ ]
As RyanDev[^] mentioned in the comment to the question, global village[^] is full of examples ')
Walkthrough: Calling a Stored Procedure Using the SqlDataSource Web Server Control[^]
How to: Execute a Stored Procedure that Returns Rows[^]
我用以下代码解决了问题:
I solved the problem with the following code:
public void ShowGV()
{
SqlConnection sqlConn = new SqlConnection(StringKoneksioni.Stringu);
using (sqlConn)
{
SqlCommand sqlCmd = new SqlCommand("procNAME", sqlConn);
sqlCmd.CommandType = CommandType.StoredProcedure;
/// The problem was here, I didn't know how to put those two following rows
sqlCmd.Parameters.Add(new SqlParameter("@ID_Person", SqlDbType.Int));
sqlCmd.Parameters["@ID_Personi"].Value = Session["ID_Person"];
sqlConn.Open();
SqlDataReader reader = sqlCmd.ExecuteReader();
gvName.DataSource = reader;
gvName.DataBind();
sqlConn.Close();
}
}
再次收到你的答复。
干杯。
Once again tank you for your reply.
Cheers.
这篇关于在使用参数化存储过程填充gridview时遇到问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文