views:

441

answers:

1

hey guys i want to fetch 3 tables in 1 single ado.net call from my ms access database, however i get an error when i am trying to do that

when i change my sql query to just fetch 1 table, my code works fine

can anyone let me know how to achieve this with ms access? because i have been doing this with sql server since ages without any problems. perhaps access does not support multiple result sets? i have not worked much with access. please help. below is my code for reference:

System.Data.OleDb.OleDbConnection con = new System.Data.OleDb.OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=DatabaseFile.mdb;Persist Security Info=True");
System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter("SELECT * FROM Table1; SELECT * FROM Table2; SELECT * FROM Table3;", con);
DataSet ds = new DataSet();
da.Fill(ds);

UPDATE: guys this does not look possible. so i had to write really stupid code to get what i wanted, complete waste of computing resources:

DataSet ds = new DataSet();

ds.Tables.Add(new DataTable("Table1"));
ds.Tables.Add(new DataTable("Table2"));
ds.Tables.Add(new DataTable("Table3"));

System.Data.OleDb.OleDbConnection con = new System.Data.OleDb.OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=DatabaseFile.mdb;Persist Security Info=True");
System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter("SELECT * FROM Table1;", con);
da.Fill(ds, "Table1");

da.SelectCommand.CommandText = "SELECT * FROM Table2;";
da.Fill(ds, "Table2");

da.SelectCommand.CommandText = "SELECT * FROM Table3;";
da.Fill(ds, "Table3");
+3  A: 

as far as I know, if your data reside inside the Access mdb, you cannot have multiple data sets. If instead you use Access to connect to an external data source, you could use pass-through queries and do that, but I do not think this is your case. (see http://support.microsoft.com/kb/126992)

pomarc
yeah looks like you are correct... i will wait for couple of hours to see if someone has a hack ;-) thanks for your help mate
Raj
@Raj: The Jet database engine does not support multiple commands in a single command text. I don't think there is a hack around this limitation. :-)
Tomalak
@tomalak - access really sucks! i will have to move to sqlite ;-)
Raj
@Raj: Access really sucks at things it has not been made for. Virtually everything sucks at stuff it hasn't been made for. ;-)
Tomalak