用多个数据表填充数据集 [英] Populating dataset with multiple data tables

查看:128
本文介绍了用多个数据表填充数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,专家,

我在填充数据集中的第二个表时遇到问题.

这是我的代码

Hi Experts,

I have a problem in populating the second table in a data set.

Here is my code

da = new oledataadapter(query_string,con)
ds = new dataset


da.fill(ds,"table_1")  --- Here data is getting populated

Again I have

query_string = "Select * from different_table"
cmd.CommandText = query_string
cmd = new oledbcommand(query_string,con)

da.fill(ds,"table_2")

-如果我在数据集可视化工具中看到,它示出了2个表,但是,当选择TABLE_2它没有显示属于TABLE_2和示出了数据TABLE_1仅.
数据
任何的想法?我要去哪里错了.

干杯
Anand

- Here if I see in dataset visualizer, it shows 2 tables but, when select table_2 it is not showing the data belong to table_2 and shows the table_1 data only.

Any idea? where am I going wrong.

Cheers
Anand

推荐答案

而不是填充DataSet,而是对DataTable使用DataAdapter.Fill.然后将其附加到您的数据集.
Instead of filling a DataSet, use DataAdapter.Fill on a DataTable instead. Then attach that to your DataSet.



您不能在OleDBCommand中使用过程吗?
创建一个过程并执行它.这将帮助您防止数据库往返.并减少网络流量.
试试这个:
Hi,
Can''t you have a procedure in OleDBCommand?
Create a procedure and execute it. This will help you to prevent database round-trips. And also decrease the network traffic.
Try this:
cmd = new oledbcommand("ProcedureName",con)
da.fill(ds)
ds.Tables[0].TableName="tbl1";
ds.Tables[0].TableName="tbl2";


若要了解如何在Access中创建过程,请参考以下链接:
http://msdn.microsoft.com/en-us/library/bb177892%28v = office.12%29.aspx [ ^ ]
http://www.vbdotnetforums.com/ms-access/31267-how-create-stored-procedure-ms-access.html [ http://stackoverflow.com/questions/3287545/how-do-i-make-a-stored-procedure-in-ms-access [ http://forums.databasejournal.com/showthread.php?31544-Create- Store-Procedure-MS-Access [ ^ ]

祝一切顺利.
--Amit


To learn how to create procedures in Access, refer the links below:
http://msdn.microsoft.com/en-us/library/bb177892%28v=office.12%29.aspx[^]
http://www.vbdotnetforums.com/ms-access/31267-how-create-stored-procedure-ms-access.html[^]
http://stackoverflow.com/questions/3287545/how-do-i-make-a-stored-procedure-in-ms-access[^]
http://forums.databasejournal.com/showthread.php?31544-Create-Store-Procedure-MS-Access[^]

All the best.
--Amit


首先,

很抱歉延迟回复[由于我不在车站内]

实际的问题是,更改查询时,每个数据适配器都需要再次实例化.即我只是如下更改

First of all,

Sorry for the delay in reply [ As I was out of station ]

The actual problem was data adapter need to be instantiated again for every when the query is changed. i.e. I just changed as below

da = New OleDbDataAdapter(wsql_query, con)
                   da.Fill(ds, "table2")



就是这样,它工作正常.

但是,正如阿米特(Amit)所说,最好将其放入程序中,以使所有事情都可以一次完成.

再次感谢阿米特(Amit)的建议和提供的链接.

干杯
Anand



That''s it, it is working fine.

But, As Amit told, it would be better to put it in procedure so that every thing gets done in one trip.

Thanks Again Amit for your suggestion and links provided.

Cheers
Anand


这篇关于用多个数据表填充数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆