从ms访问ado.net返回多个结果集 [英] return multiple result sets from ms access to ado.net
问题描述
hey们我想从我的ms访问数据库的单个ado.net调用中获取3个表,但是我得到一个错误,当我试图这样做
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
当我改变我的sql查询只是fetch 1表,我的代码工作很好
when i change my sql query to just fetch 1 table, my code works fine
任何人都可以让我知道如何实现这个与ms访问?因为我一直在做这个与sql服务器,因为年龄没有任何问题。也许访问不支持多个结果集?我没有工作多与访问。请帮忙。下面是我的代码引用:
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");
推荐答案
据我所知,在Access mdb中,你不能有多个数据集。如果相反,您使用Access连接到外部数据源,您可以使用传递查询,这样做,但我不认为这是你的情况。 (请参见 http://support.microsoft.com/kb/126992 )
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)
这篇关于从ms访问ado.net返回多个结果集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!