从MS Access到ado.net返回多个结果集 [英] return multiple result sets from ms access to ado.net
问题描述
嘿家伙,我想取3表1单ado.net电话从我的MS Access数据库,但我得到当我试图做一个错误,
当我改变我的SQL查询,就去拿一张桌子,我的code正常工作
任何人都可以让我知道如何与毫秒的存取实现这一目标?因为我一直在做这与SQL Server,因为年龄没有任何问题。也许访问不支持多个结果集?我没有太多的工作访问。请帮忙。下面是我的code,以供参考:
System.Data.OleDb.OleDbConnection CON =新System.Data.OleDb.OleDbConnection(@供应商= Microsoft.Jet.OLEDB.4.0;数据源= DatabaseFile.mdb;坚持安全信息=真);
System.Data.OleDb.OleDbDataAdapter DA =新System.Data.OleDb.OleDbDataAdapter(SELECT * FROM表1; SELECT * FROM表2; SELECT * FROM表3;CON);
的DataSet ds为新的DataSet();
da.Fill(DS);
更新:这家伙看起来并不可能。所以我不得不写的很愚蠢code得到我想要的,计算资源的完全浪费:
的DataSet ds为新的DataSet();
ds.Tables.Add(新的DataTable(表1));
ds.Tables.Add(新的DataTable(表2));
ds.Tables.Add(新的DataTable(表3));
System.Data.OleDb.OleDbConnection CON =新System.Data.OleDb.OleDbConnection(@供应商= Microsoft.Jet.OLEDB.4.0;数据源= DatabaseFile.mdb;坚持安全信息= TRUE);
System.Data.OleDb.OleDbDataAdapter DA =新System.Data.OleDb.OleDbDataAdapter(SELECT * FROM表1;CON);
da.Fill(DS,表1);
da.SelectCommand.CommandText =SELECT * FROM表2;;
da.Fill(DS,表2);
da.SelectCommand.CommandText =SELECT * FROM表3;;
da.Fill(DS,表3);
据我所知,如果你的数据驻留在访问MDB里面,你不能有多个数据集。相反,如果你使用Access连接到外部数据源,您可以使用传递查询,并做到这一点,但我不认为这是你的情况。 (见 http://support.microsoft.com/kb/126992 )
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");
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 Access到ado.net返回多个结果集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!