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
posted @ 2007-03-25 01:51  白虎  阅读(1926)  评论(0编辑  收藏  举报
非常感谢dudu,感谢博客园提供的各种服务。
联系白虎(David.Du)