我有一张桌子,我无法从中选择最高工资。这是我的代码...con.Open();SqlCommand cmd = new SqlCommand("SELECT MAX(salary) AS MAximumSalary FROM test", con);cmd.ExecuteNonQuery(); DataTable dt = new DataTable();SqlDataAdapter sda = new SqlDataAdapter(cmd);sda.Fill(dt);count =Convert.ToInt32(dt.Rows.Count.ToString());con.Close();MessageBox.Show("Maximum salary is" +count);这是我的数据库:-name salarya 10000b 31000c 17000
2 回答
隔江千里
TA贡献1906条经验 获得超10个赞
using (SqlCommand cmd = new SqlCommand("SELECT MAX(salary) FROM test"), con)
{
int maxSalary = (int)cmd.ExecuteScalar();
}
PIPIONE
TA贡献1829条经验 获得超9个赞
con.Open();
SqlCommand cmd = new SqlCommand("SELECT max(salary) FROM test"), con);
count = (int)cmd.ExecuteScalar();
con.Close();
MessageBox.Show("Maximum salary is" +count);
- 2 回答
- 0 关注
- 146 浏览
添加回答
举报
0/150
提交
取消