这样不行,你可以通过下面的方式完成:
方案1:
int i = 0;
SqlCommand mycmd = new SqlCommand("SELECT max(id) FROM order", mycon);
i = (int) mycmd.ExecuteScalar();
方案2:
int i = 0;
SqlCommand mycmd = new SqlCommand("SELECT @i = max(id) FROM order", mycon);
mycmd.ExecuteNonQuery();
i = (int)mycmd.Parameters["i"].Value;
方案二未经过验证,自己再试试吧