还是不是很理解DATASET再写了一个 ,开始是在控制台里面执行的。 感觉显示数据不是很方便后来又把那里面的代码直接拷贝的一个WINDOWS窗体的程序,感觉还好。拉了两个BUTTON空件,和一个 dataGridView的空件。
private void button1_Click(object sender, EventArgs e)
{
try
{
System.Data.SqlClient.SqlConnection sqlconnection;
System.Data.SqlClient.SqlCommand sqlcommand;
System.Data.SqlClient.SqlDataAdapter da;
sqlconnection = new System.Data.SqlClient.SqlConnection();
sqlconnection.ConnectionString = "Data Source=(local);Initial Catalog=Northwind;User ID=sa";
sqlcommand = new System.Data.SqlClient.SqlCommand();
sqlcommand.Connection = sqlconnection;
sqlcommand.CommandText = "select * from customers ";
da = new SqlDataAdapter(sqlcommand.CommandText, sqlconnection);
sqlconnection.Open();
DataSet ds = new DataSet();
da.Fill(ds, "orders");
da.SelectCommand.CommandText = "select * from employees";
da.Fill(ds, "employees");
for (int i = 0; i < ds.Tables.Count; i++)
{
Console.WriteLine("table=" + i.ToString() + "/n" + "name=" + ds.Tables[i].TableName);
}
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
this.dataGridView1.DataSource = null;
}