Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 17th, 2007, 06:21 AM
Authorized User
 
Join Date: Mar 2007
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to capture 2 SQL queries into 2 datatables

Dear friend,

i create one stored procedure with 2 sql statement like below :
.............................

SELECT Merek,COUNT(Merek) AS 'QtyMerek'
FROM SERTIFIKATUJITIPE A

SELECT Merek, Tipe, COUNT(Tipe) AS 'QtyTipe'
FROM SERTIFIKATUJITIPE A
.............................

in vb .net side, how we can capture these queries into 2 datatables ?

Tks,
hendy


 
Old January 17th, 2008, 06:42 PM
Registered User
 
Join Date: Jan 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think that it will only get the results of the last query. What you might need to do is use the dateset object to have two command objects..one for each query. A dataset can contain multiple tables. You usually only use the first one, eg, myDataSet.Tables(0). By performing two queries on the same dataset you can access them individually. Eg myDataSet.Tables(0) for the first table and myDataSet.Tables(1) for the second resultset. If you gave the tables a name in the command object, eg, "Orders" and "Products", you can use the name rather than the index number, eg, myDataSet("Products"). By having the two tables within a dataset object you can also create a relationship between them based on a key, eg, ProductId.
 
Old January 17th, 2008, 06:54 PM
Registered User
 
Join Date: Jan 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Also, if you use this method, you can use the same connection object so there shouldn't be much of a time penalty performing the two queries. Most of the time is actually taken up connecting to a database.

Remember to set all database objects (connection, command and datareader)to nothing when finished otherwise you will consume resources. You usually do this as the last step after you populate your dataset, eg, in the Finally step if you wrap your code in a try/cathc block.
 
Old March 25th, 2008, 11:47 PM
Registered User
 
Join Date: Mar 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Since you mentioned that you are using Stored Procedure. You may use cursor to pass the result back, right? If not, try to use it. It could allow you to define two cursors and declare them as in/out parameters.

Eins Tsang
 
Old March 26th, 2008, 09:31 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I thought that in a stored procedure you needed to use SELECT queries as
Code:
      SELECT <flds>
      FROM   <tbl>
      WHERE  <conditions>
      INTO   <a cursor, or variable>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Combine sql queries snufse SQL Server 2005 16 June 17th, 2008 03:47 PM
Capture Sql server Error happygv SQL Server 2000 19 May 10th, 2007 12:55 AM
Anyone Expert in SQL Queries? itHighway HTML Code Clinic 3 June 3rd, 2005 09:57 AM
Anyone Expert in SQL Queries itHighway Classic ASP Basics 2 May 24th, 2005 03:37 AM
pls help SQL Queries sush_blr SQL Server 2000 2 February 1st, 2005 01:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.