错误:为什么“10”值后没有递增?

时间:2013-09-26 08:34:50

标签: c# vb.net

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();

1 个答案:

答案 0 :(得分:5)

如果CourseCode是char / varchar或任何其他字符串,那么9大于10

也许这会有所帮助:

SELECT MAX(CONVERT(INT,CourseCode)) FROM CourseMaster