我试图在下面的这个查询中返回成员 ID。如果我像查询一样运行查询,我会得到 20,但是当我执行代码时它返回零。我在这里做错了什么?
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;
}