-2

TableName = CourseMaster

Column Name = CourseCode

每次需要最大值= 9 ..!和 9 + 1 = 10 ..(值增加 1 )..!

为什么 nt 取 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();
4

1 回答 1

5

如果 CourseCode 是 char/varchar 或任何其他类似类型的字符串,则9大于10.

也许这会有所帮助:

SELECT MAX(CONVERT(INT,CourseCode)) FROM CourseMaster
于 2013-09-26T08:43:06.300 回答