return multiple result sets from ms access to ado.net

别来无恙 提交于 2019-12-11 07:29:49

问题


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");

回答1:


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)



来源:https://stackoverflow.com/questions/726263/return-multiple-result-sets-from-ms-access-to-ado-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!