473,395 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

load multi sql statement results into a dataset?

yarbrough40
320 100+
I've only dealt with firing a single SQL statement at a SQLServer table and returning a single result... easy....

however....
is there a way to fire a dual sql command and load the results into respective tables within a dataset?.. I'm thinking something along these lines (this code of course does not work)
Expand|Select|Wrap|Line Numbers
  1. Dim ds As New DataSet
  2. Dim dt1 As DataTable = ds.Tables(0)
  3. Dim dt2 As DataTable = ds.Tables(1)
  4.  
  5. Dim con As New OleDbConnection(MyConnectionString)
  6.         Dim cmd As New OleDbCommand
  7.         Dim dr As OleDbDataReader
  8.         Dim sql As String
  9.  
  10. ''''''''''''NOTICE HOW THERE ARE TWO SELECT STATEMENTS HERE
  11.         sql = "Select * from Holidays; Select * from UserTable"
  12.  
  13. con.Open()
  14.         cmd.CommandText = sql
  15.         cmd.Connection = con
  16.         dr = cmd.ExecuteReader
  17. While dr.read
  18.    dt1.Load(dr)
  19.    dt2.Load(dr)
  20. End While
  21.  
  22.  
  23.  
Mar 25 '10 #1

✓ answered by CroCrew

Hello yarbrough40,

I don’t know of anyway to fire off two individual SQL select commands at the same time into one dataset that can be individually accessed through the dataset.

But, I can show you a way to fire off two individual SQL select commands into one dataset.

Expand|Select|Wrap|Line Numbers
  1.         Dim dbConnection As MySqlConnection = New MySqlConnection()
  2.         dbConnection.ConnectionString = ConnectionString()
  3.  
  4.         Dim mylocalDataSet As DataSet = New DataSet
  5.  
  6.         Dim myDataAdapterOne As New MySqlDataAdapter("SELECT Author FROM Books ORDER BY KeyID", dbConnection)
  7.         myDataAdapterOne.Fill(mylocalDataSet, "myData1")
  8.  
  9.         Dim myDataAdapterTwo As New MySqlDataAdapter("SELECT Title FROM Books ORDER BY KeyID", dbConnection)
  10.         myDataAdapterTwo.Fill(mylocalDataSet, "myData2")
  11.  
  12.         If dbConnection.State = Data.ConnectionState.Closed Then
  13.             dbConnection.Open()
  14.         End If
  15.  
  16.         TextBox1.Text = mylocalDataSet.Tables("mydata1").Rows(0).Item("Author").ToString
  17.         TextBox2.Text = mylocalDataSet.Tables("mydata2").Rows(0).Item("Title").ToString
  18.  
  19.         If dbConnection.State = Data.ConnectionState.Open Then
  20.             dbConnection.Close()
  21.             dbConnection.Dispose()
  22.         End If
  23.  
Hope this helps.

Happy Coding,
CroCrew~

3 2584
CroCrew
564 Expert 512MB
Hello yarbrough40,

I don’t know of anyway to fire off two individual SQL select commands at the same time into one dataset that can be individually accessed through the dataset.

But, I can show you a way to fire off two individual SQL select commands into one dataset.

Expand|Select|Wrap|Line Numbers
  1.         Dim dbConnection As MySqlConnection = New MySqlConnection()
  2.         dbConnection.ConnectionString = ConnectionString()
  3.  
  4.         Dim mylocalDataSet As DataSet = New DataSet
  5.  
  6.         Dim myDataAdapterOne As New MySqlDataAdapter("SELECT Author FROM Books ORDER BY KeyID", dbConnection)
  7.         myDataAdapterOne.Fill(mylocalDataSet, "myData1")
  8.  
  9.         Dim myDataAdapterTwo As New MySqlDataAdapter("SELECT Title FROM Books ORDER BY KeyID", dbConnection)
  10.         myDataAdapterTwo.Fill(mylocalDataSet, "myData2")
  11.  
  12.         If dbConnection.State = Data.ConnectionState.Closed Then
  13.             dbConnection.Open()
  14.         End If
  15.  
  16.         TextBox1.Text = mylocalDataSet.Tables("mydata1").Rows(0).Item("Author").ToString
  17.         TextBox2.Text = mylocalDataSet.Tables("mydata2").Rows(0).Item("Title").ToString
  18.  
  19.         If dbConnection.State = Data.ConnectionState.Open Then
  20.             dbConnection.Close()
  21.             dbConnection.Dispose()
  22.         End If
  23.  
Hope this helps.

Happy Coding,
CroCrew~
Apr 5 '10 #2
yarbrough40
320 100+
Ahh, I see. Easier than I thought. Thanks!
Apr 6 '10 #3
CroCrew
564 Expert 512MB
Anytime.

Happy Coding,
CroCrew~
Apr 6 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Shabam | last post by:
A web application of mine developed using C# + MS SQL runs fine normally. However when I stress test it with a load testing software (using about 60 simultaneous users) some instances start...
1
by: paul-esposito | last post by:
Okay, so I'm the DBA not a developer, but I need a sanity check. All the data access to the database is controlled by Stored Procedures, the procedures are really granular, basically every table...
1
by: Steve | last post by:
C# I have a DataSet defined in my project that consists of one main table and 3 child tables. I have a SQL statement that can retrieve all the information for this structure, but how do I...
1
by: Tom G | last post by:
The following is a small sample of my XML Data. When I load it to a dataset it only loads the 'Zone' elements and ignores loading the 'Field' elements. <zone id="1234" name="EMPLOYMENT_INFO">...
0
by: Gareth Stretch | last post by:
Hi Guys. i am using C#.net connecting to an Access database using OleDbConnection i am using the following select Statement to join 3 tables string strdvds = "SELECT dvd.name,...
9
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter...
23
by: Kaz Kylheku | last post by:
I've been reading the recent cross-posted flamewar, and read Guido's article where he posits that embedding multi-line lambdas in expressions is an unsolvable puzzle. So for the last 15 minutes...
1
by: dbagirltx | last post by:
We have done some testing with mixed and forgotten results. So I'm hoping that asking here can clarify some issues for us. Right now we do one weekly warm backup. Throughout the week there are...
1
by: VB Programmer | last post by:
I have a SqlDataSource I setup on an ASP.NET 2.0 webform. I setup the SELECT statement and it has 1 parameter, @ProductId. How do I, using VB.NET, store the results of that SELECT statement...
5
by: Trevisc | last post by:
Happy Thursday Everyone, I am trying to create a parameter that is one long varchar but that will be used in a SQL statement IN function: //string queryString = GetCurrentTitles(); //Below is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.