代码如下:
private int GC(int GradeId,int ClassId)
{
int result = -1;
string sql = string.Format("select count(*) from Class where ClassId={0} and GradeId={1}", ClassId, GradeId);
try
{
SqlCommand command = new SqlCommand(sql, SQL.connection);
SQL.connection.Open();
result = (int)command.ExecuteScalar();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
SQL.connection.Close();
}
return result;
}
我在数据库里面用SQL查询可以查到结果为1 但是在C#中返回值就是0了 这是什么问题啊
private int GC(int GradeId,int ClassId)
{
int result = -1;
string sql = string.Format("select count(*) from Class where ClassId={0} and GradeId={1}", ClassId, GradeId);
try
{
SqlCommand command = new SqlCommand(sql, SQL.connection);
SQL.connection.Open();
result = (int)command.ExecuteScalar();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
SQL.connection.Close();
}
return result;
}
我在数据库里面用SQL查询可以查到结果为1 但是在C#中返回值就是0了 这是什么问题啊
查询结果返回值是1
private int GC(int GradeId,int ClassId)
{
int result = -1;
string sql = string.Format("select count(*) from Class where ClassId={0} and GradeId={1}", ClassId, GradeId);
try
{
SqlCommand command = new SqlCommand(sql, SQL.connection);
SQL.connection.Open();
result = (int)command.ExecuteScalar();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
SQL.connection.Close();
}
return result;
}是GradeId和ClassId的问题 我在select count(*) from Class where ClassId={0} and GradeId={1}把{0}和{1}换成2和1就没问题了 但是为什么定义一个int型的就会出问题呢
在查询分析器执行,参数顺序
SQL 不会 执行 隐形转换吗?