Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi Experts,

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

Here is my code
C#
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")
- 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
Posted
Updated 12-Jul-12 21:08pm
v2
Comments
Sander Rossel 13-Jul-12 3:08am    
Added a code block for readability.

Instead of filling a DataSet, use DataAdapter.Fill on a DataTable instead. Then attach that to your DataSet.
 
Share this answer
 
Comments
Sander Rossel 13-Jul-12 3:07am    
My 5. Things don't always have to be that complicated :)
OriginalGriff 13-Jul-12 3:16am    
I like simple! :laugh:
Sander Rossel 13-Jul-12 3:50am    
KISS! :)
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:
C#
cmd = new oledbcommand("ProcedureName",con)
da.fill(ds)
ds.Tables[0].TableName="tbl1";
ds.Tables[0].TableName="tbl2";

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
 
Share this answer
 
v2
Comments
Anand Rangaraju 13-Jul-12 3:21am    
Hi Amit,

Thanks for quick post.

The database is in Access and I do not know how to create a proc in access db.

First of all is it possible to create a proc in access DB?

Thanks
Anand
_Amy 13-Jul-12 8:01am    
Hi, Please check my updated answer.
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

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


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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900