【发布时间】:2014-07-29 19:15:07
【问题描述】:
我正在尝试返回 MAX 值,但它一直返回 0。
string stateValue = "CA";
SqlCommand cmd = new SqlCommand("SELECT MAX(Population) FROM TestData WHERE State=" + stateValue);
cmd.Parameters.Add("@Population", SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
DBConnection.Instance.execNonQuery(cmd);
int population = (int)cmd.Parameters["@Population"].Value;
在DBConnection 类中,这是execNonQuery 函数:
public int execNonQuery(string sCmd, CommandType cmdType)
{
SqlCommand cmd = new SqlCommand(sCmd, m_sqlDataBase);
cmd.CommandType = cmdType;
try
{
m_sqlDataBase.Open();
}
catch { }
return cmd.ExecuteNonQuery();
}
【问题讨论】:
标签: c# sql sql-server max