下面是我的代码。我想要'int'类型的函数,它将返回'int'value.Query在这段代码中返回一个'int'值,但是在这段代码中返回值是什么?我无法在此处写回返get_number。那我会怎么做?从查询返回int值的int型函数的返回值是什么
我的代码:
public int CheckMatch(CourseSchedule courseInfo)
{
try
{
ConnectionObj.Open();
string get_number = "SELECT count(c_t_id) FROM course_teacher_table WHERE room_number = '" + courseInfo.RoomNumber + "' and class_days = '" + courseInfo.Days + "' and class_time = '" + courseInfo.ClassTime + "'";
CommandObj.CommandText = get_number;
CommandObj.ExecuteNonQuery();
return '???'
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (ConnectionObj != null && ConnectionObj.State == ConnectionState.Open)
{
ConnectionObj.Close();
}
}
}
此代码容易受到sql注入攻击。它实际上是乞求被黑客攻击。 –
您应该始终使用[参数化查询](http://blog.codinghorror.com/give-me-parameterized-sql-or-give-me-death/)。这种字符串连接对于_SQL Injection_攻击是开放的。 –
@JoelCoehoorn C#允许多个查询吗? – EaterOfCode