[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Can I load one dataset with more than one datatables in this way?

Posted on 2006-07-12
7
Medium Priority
?
219 Views
Last Modified: 2010-04-23
I tried the following in vs 2003 win form app.

Dim arParms() As SqlParameter = New SqlParameter(0) {}
        arParms(0) = New SqlParameter("@P1", SqlDbType.VarChar)
        arParms(0).Value = JobID
            dsOrder = SqlHelper.ExecuteDataset(cn_str_W, CommandType.StoredProcedure, "CT_getOrder", arParms)
            dsOrder.Tables(0).TableName = "order"
            dsOrder = SqlHelper.ExecuteDataset(cn_str_Q, CommandType.StoredProcedure, "CT_getProduct", arParms)
            dsOrder.Tables(1).TableName = "Product"

I got index out of range exception on last line. How do I set the index first? The code is fine if I removed last two lines.

Thanks!
0
Comment
Question by:ommer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 17094837
We'd need to see SqlHelper. However, you're assigning the output from ExecuteDataset to the dataset twice, which means that you're overwriting the dataset the second time you call it. So, effectively, you're only making the second call.
0
 

Author Comment

by:ommer
ID: 17095472
The sqlHelper class is from Microsoft Data Access Application Block. I don't have the source code right now.

Anyway, as I understand, one dataset can have many data tables in it. This is new to me, given my ado recordset background. How do you typically load the 2nd table to the dataset? Do you have to make the stored procedures returns multiple sets, or do I need to "pre-dimension" the dataset-datatables?

0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 17095638
Generally, you'd load the second set of data into a table, then add that table to the dataset...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:ZeonFlash
ID: 17096227
A fan of SqlHelper myself, I've tinkered around and found that you can do the following (assuming that your 2nd execution will return only 1 table):

dsOrder = SqlHelper.ExecuteDataset(cn_str_W, CommandType.StoredProcedure, "CT_getOrder", arParms)
dsOrder.Tables(0).TableName = "order"
dsOrder.Tables.Add(SqlHelper.ExecuteDataset(cn_str_Q, CommandType.StoredProcedure, "CT_getProduct", arParms).Tables(0))
dsOrder.Tables(1).TableName = "Product"
0
 

Author Comment

by:ommer
ID: 17099359
ZeonFlash,

When I use next line from your reply, do I use ...Tables(0) or ...Tables(1)? It seems neither works for me.

dsOrder.Tables.Add(SqlHelper.ExecuteDataset(cn_str_Q, CommandType.StoredProcedure, "CT_getProduct", arParms).Tables(0))

Thank a lot!
0
 
LVL 17

Accepted Solution

by:
ZeonFlash earned 200 total points
ID: 17100174
Yikes, oversight on my part.  You're probably getting a "DataTable already belongs to another DataSet" error.  You need to create a copy of the table to add to the dataset, not use the one returned by SqlHelper directly.  Try this:

dsOrder.Tables.Add(SqlHelper.ExecuteDataset(cn_str_Q, CommandType.StoredProcedure, "CT_getProduct", arParms).Tables(0).Copy)

0
 

Author Comment

by:ommer
ID: 17100786
Yap, that works. It will save me couple datasets. More importantly, I have learnt the dotnet way. Thanks!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question