gpt4 book ai didi

C# SQL 存储过程调用值

转载 作者:太空狗 更新时间:2023-10-30 01:01:44 26 4
gpt4 key购买 nike

尝试与数据库通信时,我对如何将值作为参数(例如 itemID)传递并取回具有此 ID 的记录感到有点困惑。

这是我的存储过程:

ALTER PROCEDURE [dbo].[sp_lightItem]
(
@itemID INT
)
AS
BEGIN

SELECT [itemID],
[itemName],
[itemLocation],
[itemChBy]
FROM [dbo].[Item]
WHERE itemSystemType='E' and itemID=@itemID ORDER BY itemID DESC;
END

这是我到目前为止的 C# 代码..

 public string LoadItemNew(int ItemID)
{
var acf = new AcFunctions();
var newstorevalue = SqlHelper.ExecuteDataset(acf.AcConn(), "sp_lightItem", ItemID);
}

正如您在存储过程中看到的那样,我想要取回这 4 个元素:

[itemID],[itemName],[itemLocation],[itemChBy]

不幸的是,我不知道如何取回它们/如何在 C# 函数中调用它们。
欢迎任何帮助。

最佳答案

我没有足够的 repo 来评论,你能提供

的定义吗
AcFunctions();

我确定你一定会返回 ConnectionString

试试这个

 public string LoadItemNew(int ItemID)
{
var acf = new AcFunctions();
var newstorevalue = SqlHelper.ExecuteDataset(acf.AcConn(), "sp_lightItem", new SqlParameter ("@itemID",ItemID));
}

编辑 1试试这个

  public string LoadItemNew(int ItemID)
{
List<string> testList = new List<string>();

var acf = new AcFunctions();


var newstorevalue = SqlHelper.ExecuteReader(acf.AcConn(), "sp_lightItem", new SqlParameter ("@itemID",ItemID));

if(newstorevalue.HasRows)
{





while(newstorevalue.Read())
{
testList.Add(newstorevalue["itemID"].ToString());
testList.Add(newstorevalue["itemName"].ToString());
testList.Add(newstorevalue["itemLocation"].ToString());
testList.Add(newstorevalue["itemChBy"].ToString());
}

}

}

关于C# SQL 存储过程调用值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37154845/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com