我正在执行3个选择查询,现在我想将3个不同查询的结果存储在不同的数据集表中,这样我就可以在不同的网格视图中显示不同的表,但是我得到索引超出范围异常,下面是我的代码 -
public DataSet viewdeal1()
{
//string connectionString = "Data Source=INGNRILPSQL02;Initial Catalog=AHD08_A40;Persist Security Info=True;User ID=a36;Password=a36";
string connectionString = @"Data Source=DELL-PC\SQLEXPRESS;Initial Catalog=Nikita;Integrated Security=True";
string queryString3 = "Select PS3_Dealer.DealerID,DealerName,ContactNo,NoOfVehicles,CommittedDate from PS3_Dealer where CommittedDate<GETDATE()";
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
SqlCommand sc = new SqlCommand(queryString3, connection);
SqlDataAdapter da = new SqlDataAdapter(sc);
DataSet ds = new DataSet();
// sc.ExecuteNonQuery();
da.Fill(ds.Tables[0]);
string queryString1 = "Select PS3_Dealer.DealerID,DealerName,ContactNo,NoOfVehicles,CommittedDate from PS3_Dealer inner join (select DealerID from PS3_Vehicle inner join PS3_VehicleBooking on PS3_Vehicle.VehicleID!=PS3_VehicleBooking.VehicleID) as H on PS3_Dealer.DealerID=H.DealerID";
SqlCommand sc1 = new SqlCommand(queryString1, connection);
SqlDataAdapter da1 = new SqlDataAdapter(sc1);
// sc.ExecuteNonQuery();
da1.Fill(ds.Tables[1]);
string queryString2 = "Select PS3_Dealer.DealerID,DealerName,ContactNo,NoOfVehicles,CommittedDate from PS3_Dealer inner join (Select DealerID from PS3_Vehicle inner join PS3_VehicleBooking on PS3_Vehicle.VehicleID=PS3_VehicleBooking.VehicleID where EndDate< GETDATE()) as Q on PS3_Dealer.DealerID=Q.DealerID";
SqlCommand sc2 = new SqlCommand(queryString2, connection);
SqlDataAdapter da2 = new SqlDataAdapter(sc2);
// sc.ExecuteNonQuery();
da2.Fill(ds.Tables[2]);
connection.Close();
return ds;
}