gpt4 book ai didi

c# - 将数据类型 varchar 转换为 bigint 时出错。内联 sql 语句

转载 作者:太空宇宙 更新时间:2023-11-03 18:17:49 24 4
gpt4 key购买 nike

这是我用来从带有 MerchantID 的数据库中获取 LocationID 的代码。我从填充数据集部分得到一个异常(exception)。请帮帮我,。错误是将数据类型 varchar 转换为 bigint 时出错。

public DataSet getLocationID(long MerchantID)
{
//long LOCID = null;
try
{
SqlParameter[] parameters = new SqlParameter[]
{
new SqlParameter("@merchantID",MerchantID)
};

string strCommandText = "Select LocationID from Merchant_Location where MerchantID ='@merchantID' order by LocationID ASC";

Debug.WriteLine(strCommandText);

DataSet pds = new DataSet();

SqlHelper.FillDataset(DbConnString, System.Data.CommandType.Text, strCommandText, pds, new string[] { "LocID" }, parameters);
return pds;
}
catch (Exception ex)
{
//LogError("Error Occurred When Retrieving LocationID: " + MerchantID.ToString(), ex);
return null;
}
}

最佳答案

去掉 @merchantID 周围的单引号在您的查询文本中,假设 MerchantID 是一个 bigint。

关于c# - 将数据类型 varchar 转换为 bigint 时出错。内联 sql 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3613954/

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