?
Solved

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

Posted on 2006-07-12
7
Medium Priority
?
214 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

770 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