资 源 简 介
显示Customers数据表第3-7条记录,C#操作数据库显示Customers数据表第3-7条记录,其实做出来例子,才知道,很简单啊,不过需要把数据库先连接好,看如下代码:
private void button1_Click(object sender, EventArgs e)
{//显示Customers数据表第3-7条记录
SqlConnection MyConnection=new SqlConnection();
MyConnection.ConnectionString = @"Data Source =.SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True";
MyConnection.Open();
SqlCommand MyCommand =new SqlCommand("Select * From Customers ORDER BY CustomerID", MyConnection);
DataSet MySet = new DataSet();
SqlDataAdapter MyAdapter = new SqlDataAdapter(MyCommand);
MyAdapter.Fill(MySet, 2, 5, "Customers");
this.dataGridView1.DataSource=MySet.Tables["Customers"];
}