c#关于查寻数据库的行数
1private void button1_Click(object sender, EventArgs e)
2{
3 // 数据库连接
4 SqlConnection con = new SqlConnection("server=.;database=Northwind;uid=sa;pwd=0");
5 con.Open();
6
7 //查询记录数
8 SqlCommand cmd = new SqlCommand("select count(*) from orders", con);
9
10 //反回首行首列
11 int count = Convert.ToInt32(cmd.ExecuteScalar());
12
13 //显示记录数
14 MessageBox.Show("Northwind数据库orders表共有 " + count + " 条记录! ");
15
16}
17
2{
3 // 数据库连接
4 SqlConnection con = new SqlConnection("server=.;database=Northwind;uid=sa;pwd=0");
5 con.Open();
6
7 //查询记录数
8 SqlCommand cmd = new SqlCommand("select count(*) from orders", con);
9
10 //反回首行首列
11 int count = Convert.ToInt32(cmd.ExecuteScalar());
12
13 //显示记录数
14 MessageBox.Show("Northwind数据库orders表共有 " + count + " 条记录! ");
15
16}
17
白虎
Hello! I Am David.DU.