I have the following function:
private static DataTable GetDataFromDatabase(DateTime myDate)
{
DataTable table = new DataTable();
table.Columns.AddRange(new DataColumn[]
{
new DataColumn("Event"), new DataColumn("Room"),
new DataColumn("From"), new DataColumn("To"), new DataColumn("Persons"),
new DataColumn("Equipment"), new DataColumn("Catering")
});
string strSQL = "SELECT distinct ID FROM VIEW_RAUMBUCHUNG_DISPO " +
"WHERE BOOKSTATUS >= 1 AND convert(char, von,104) = '" +
BookITVbSQL.to_104(myDate) + "'";
SqlDataReader objRS;
objRS = SQLrunReaderDP(strSQL);
while (objRS.Read())
{
using (SqlConnection con = new SqlConnection(GetConnectionString()))
{
using (SqlCommand cmd = con.CreateCommand())
{
con.Open();
cmd.CommandText = "SELECT distinct EVENT, ROOM, CONVERT(char(5), from, 108) " +
"FROM, CONVERT(char(5), to, 108) TO, PERSONS FROM VIEW_RAUMBUCHUNG_DISPO " +
"WHERE ID = '" + objRS["ID"] + "'; " +
"SELECT EQUIPMENTNAME FROM EQUIPMENT WHERE BUCHUNG_ID = '" + objRS["ID"] +
"' and STATUS = '2'; " +
"SELECT CATERINGNAME FROM CATERING WHERE BUCHUNG_ID = '" + objRS["ID"] +
"' and STATUS = '1';";
using (SqlDataReader rdr = cmd.ExecuteReader())
{
do
{
while (rdr.Read())
{
table.Rows.Add(
rdr["EVENT"],
rdr["ROOM"],
rdr["FROM"],
rdr["TO"],
rdr["PERSONS"] );
}
}
while (rdr.NextResult());
rdr.Close();
}
con.Close();
}
}
}
return table;
}
This works fine for the first Statement. I can get all the Data from the five Columns. But how can i Add the Columns from the other two Querys to the same Row?
If i try:
while (rdr.Read())
{
table.Rows.Add(
rdr["EVENT"],
rdr["ROOM"],
rdr["FROM"],
rdr["TO"],
rdr["PERSONS"],
rdr["EQUIPMENTNAME"]);
}
so iam getting an IndexOutOfRange - Exception. Can someone help me with that please?