TableName = CourseMaster
Column Name = CourseCode
永远需要最大值= 9 ..! 并且9 + 1 = 10 ..(值为1)...!
为什么它取MAX值为10? 有人请帮忙,告诉我哪里错了...... ??
// Finding Max Term CourseCode
string query1 = "SELECT MAX(CourseCode) FROM CourseMaster ";
SqlCommand comm1 = new SqlCommand(query1, connection);
comm1.CommandType = CommandType.Text;
string s;
s = comm1.ExecuteScalar().ToString();
label3.Text = s;
int i;
i = Convert.ToInt32(s) + 1;
s = i.ToString();
label7.Text = s;
comm1.ExecuteNonQuery();
comm1.Connection.Close();
答案 0 :(得分:5)
如果CourseCode是char / varchar或任何其他字符串,那么9
大于10
。
也许这会有所帮助:
SELECT MAX(CONVERT(INT,CourseCode)) FROM CourseMaster