在下面的查询中,我正在尝试返回成员id。如果我像运行查询一样运行查询,我会得到20,但当我执行代码时,它会返回0。我在这里做错了什么?
public int GetMemberID(string guid)
{
string strConectionString = ConfigurationManager.AppSettings["DataBaseConnection"];
string StrSql = "SELECT MemberID FROM MEMBERS WHERE (Guid = @GuidID)";
int memberId;
using (var connection = new SqlConnection(strConectionString))
using (var command = new SqlCommand(StrSql, connection))
{
command.Parameters.Add("@GuidID", SqlDbType.Int).Value = guid;
memberId = (int)command.ExecuteScalar();
}
return memberId;
}发布于 2011-12-03 12:20:01
guid变量不是int。
command.Parameters.Add("@GuidID", SqlDbType.VarChar).Value = guid;发布于 2011-12-03 12:20:58
您的参数@GuidID是Int类型吗?确保它是正确的。
https://stackoverflow.com/questions/8365473
复制相似问题