[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-07-12
7
Medium Priority
?
223 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
  • 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
Independent Software Vendors: 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

834 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