473,408 Members | 1,976 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,408 software developers and data experts.

Fill Dataset with two tables

This is probably a simple question but I want to make sure I am doing
it right.

I have a spoc with two select statements which results in two tables.

Very Basic

---------------------------------------------------------------------------------
@strProductCode nvarchar (50)

select *
from tblProducts
where strproductCode = @strProductCode

select * from tblJctProductColors

-----------------------------------------------------------------------------------

I will eventually set up a relationship between the two but first I
need to get them into one dataset as two tables. I am not sure of the
code. I have looked through past posts but I am still confused. Can
someone help. This is what I have so far.

-------------------------------------------------------------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'retreive the prodcut code
Dim strProductCode = Request.QueryString("ProductCode")

'create the connection string
Dim connection As New SqlConnection(connectionString)
'Create and initialize the command Object
Dim command As New SqlCommand("New_getDetailsTables",
connection)
command.CommandType = CommandType.StoredProcedure
' Add an input parameter and supply a value for it
command.Parameters.Add("@strProductCode", SqlDbType.VarChar,
50)
command.Parameters("@strProductCode").Value = strProductCode
Dim mySqlDataAdapter As SqlDataAdapter = New
SqlDataAdapter(command)
Dim dsGetProducts As New DataSet
mySqlDataAdapter.Fill(dsGetProducts, "Products")

DataList1.DataSource = dsGetProducts.Tables("products")
DataList1.DataBind()

End Sub

I have got the dataset returning values from the first table in the
sproc but I need values from the second table.

I would like to have two tables from in the dataset. Products and
colors. The first select statement is products and the second is
colors. Can someone advise?

Thanks for any help!
Laura K

Mar 2 '06 #1
6 2441
your code is currently loading two tables. the first table "Products"
contrain the data from tblProduct. the second table "Products_1" (auto
named) contains the data from the table tblJctProductColors. you can rename
the second table after the fill.

-- bruce (sqlwork.com)


"Laura K" <kl*****@charter.net> wrote in message
news:11*********************@j33g2000cwa.googlegro ups.com...
This is probably a simple question but I want to make sure I am doing
it right.

I have a spoc with two select statements which results in two tables.

Very Basic

---------------------------------------------------------------------------------
@strProductCode nvarchar (50)

select *
from tblProducts
where strproductCode = @strProductCode

select * from tblJctProductColors

-----------------------------------------------------------------------------------

I will eventually set up a relationship between the two but first I
need to get them into one dataset as two tables. I am not sure of the
code. I have looked through past posts but I am still confused. Can
someone help. This is what I have so far.

-------------------------------------------------------------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'retreive the prodcut code
Dim strProductCode = Request.QueryString("ProductCode")

'create the connection string
Dim connection As New SqlConnection(connectionString)
'Create and initialize the command Object
Dim command As New SqlCommand("New_getDetailsTables",
connection)
command.CommandType = CommandType.StoredProcedure
' Add an input parameter and supply a value for it
command.Parameters.Add("@strProductCode", SqlDbType.VarChar,
50)
command.Parameters("@strProductCode").Value = strProductCode
Dim mySqlDataAdapter As SqlDataAdapter = New
SqlDataAdapter(command)
Dim dsGetProducts As New DataSet
mySqlDataAdapter.Fill(dsGetProducts, "Products")

DataList1.DataSource = dsGetProducts.Tables("products")
DataList1.DataBind()

End Sub

I have got the dataset returning values from the first table in the
sproc but I need values from the second table.

I would like to have two tables from in the dataset. Products and
colors. The first select statement is products and the second is
colors. Can someone advise?

Thanks for any help!
Laura K

Mar 2 '06 #2
Try a union join.

e.g.

SELECT * FROM Table1
UNION
SELECT * FROM Table2

"Laura K" <kl*****@charter.net> wrote in message
news:11*********************@j33g2000cwa.googlegro ups.com...
This is probably a simple question but I want to make sure I am doing
it right.

I have a spoc with two select statements which results in two tables.

Very Basic

---------------------------------------------------------------------------------
@strProductCode nvarchar (50)

select *
from tblProducts
where strproductCode = @strProductCode

select * from tblJctProductColors

-----------------------------------------------------------------------------------

I will eventually set up a relationship between the two but first I
need to get them into one dataset as two tables. I am not sure of the
code. I have looked through past posts but I am still confused. Can
someone help. This is what I have so far.

-------------------------------------------------------------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'retreive the prodcut code
Dim strProductCode = Request.QueryString("ProductCode")

'create the connection string
Dim connection As New SqlConnection(connectionString)
'Create and initialize the command Object
Dim command As New SqlCommand("New_getDetailsTables",
connection)
command.CommandType = CommandType.StoredProcedure
' Add an input parameter and supply a value for it
command.Parameters.Add("@strProductCode", SqlDbType.VarChar,
50)
command.Parameters("@strProductCode").Value = strProductCode
Dim mySqlDataAdapter As SqlDataAdapter = New
SqlDataAdapter(command)
Dim dsGetProducts As New DataSet
mySqlDataAdapter.Fill(dsGetProducts, "Products")

DataList1.DataSource = dsGetProducts.Tables("products")
DataList1.DataBind()

End Sub

I have got the dataset returning values from the first table in the
sproc but I need values from the second table.

I would like to have two tables from in the dataset. Products and
colors. The first select statement is products and the second is
colors. Can someone advise?

Thanks for any help!
Laura K

Mar 2 '06 #3
Hello Laura,

If you have a stored procedure with two select statements in it:

=-=-=-=-
....
select *
from tblProducts
where strproductCode = @strProductCode

select * from tblJctProductColors
....
=-=-=-=-

and you call SqlDataAdapter.Fill(dataSet), you will find there are two
tables (rowsets) returned upon return from the Fill() method (provided both
select statements return data. If you want to examine the DataSet, you can
set a breakpoint and open a watch window to verify the contents of the
dataSet object.)

You can then name the tables and specify the relationship between the tables
using syntax similar to:

=-=-=-=-=-=-
dataSet.Table[0].TableName = "Products";
dataSet.Table[1].TableName = "Colors";

dataSet.Relations.Add("ProductColor",
dsTables["Products"].Columns["ProductID"],
dsTables["ProductColor"].Columns["ColorID"]);
=-=-=-=-=-=-

Hope this helps.
--
brians
http://www.limbertech.com
"Laura K" wrote:
This is probably a simple question but I want to make sure I am doing
it right.

I have a spoc with two select statements which results in two tables.

Very Basic

---------------------------------------------------------------------------------
@strProductCode nvarchar (50)

select *
from tblProducts
where strproductCode = @strProductCode

select * from tblJctProductColors

-----------------------------------------------------------------------------------

I will eventually set up a relationship between the two but first I
need to get them into one dataset as two tables. I am not sure of the
code. I have looked through past posts but I am still confused. Can
someone help. This is what I have so far.

-------------------------------------------------------------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'retreive the prodcut code
Dim strProductCode = Request.QueryString("ProductCode")

'create the connection string
Dim connection As New SqlConnection(connectionString)
'Create and initialize the command Object
Dim command As New SqlCommand("New_getDetailsTables",
connection)
command.CommandType = CommandType.StoredProcedure
' Add an input parameter and supply a value for it
command.Parameters.Add("@strProductCode", SqlDbType.VarChar,
50)
command.Parameters("@strProductCode").Value = strProductCode
Dim mySqlDataAdapter As SqlDataAdapter = New
SqlDataAdapter(command)
Dim dsGetProducts As New DataSet
mySqlDataAdapter.Fill(dsGetProducts, "Products")

DataList1.DataSource = dsGetProducts.Tables("products")
DataList1.DataBind()

End Sub

I have got the dataset returning values from the first table in the
sproc but I need values from the second table.

I would like to have two tables from in the dataset. Products and
colors. The first select statement is products and the second is
colors. Can someone advise?

Thanks for any help!
Laura K

Mar 2 '06 #4
Great it is coming together. I have the tables under control. Now I am
working on the relationship. I have received the following error
T"hese columns don't currently have unique values."
My updated code is as follows:

Dim dsGetProducts As New DataSet
mySqlDataAdapter.Fill(dsGetProducts, "Products")

dsGetProducts.Tables(0).TableName = "Products"
dsGetProducts.Tables(1).TableName = "Colors"

dsGetProducts.Relations.Add("ProductsToColors",
dsGetProducts.Tables("products").Columns("intProdu ctID"),
dsGetProducts.Tables("colors").Columns("intProduct ID"))

Now this is a parent child relationship. The product table returns a
list of items which match the productcode. ProductID is the PK. The
color table has productID as a FK. and should return a list of colors
for each productID.

I am obviously missing something.

Thanks for the help so far. I see a light at the end of the tunnel
---------

Laura K

Mar 2 '06 #5
Figured the error out. Added a ,false to the relationship and all is
well...so far. Thanks for all the help.

Mar 2 '06 #6
Good you have seen a light at the end of the tunnel :)
Patrick
"Laura K" <kl*****@charter.net> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
Figured the error out. Added a ,false to the relationship and all is
well...so far. Thanks for all the help.

Mar 3 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Stanav | last post by:
Hello all, I'm developing a web application using VB.Net 2003 and Framework 1.1. This application queries an AS/400 database. I'm using the IBM OleDb provider that came with IBM Client Access for...
4
by: Dave Edwards | last post by:
I understand that I can fill a datagrid with multiple queries, but I cannot figure out how to fill a dataset with the same query but run against multiple SQL servers, the query , table structure...
1
by: Nikolay Petrov | last post by:
How to fill dataset with multiple tables and set their relaition? Can I get the relations from the SQL server? Also I would like to do it using stored procedures. TIA
1
by: scottin | last post by:
I setup the dataset, which is the datasource for a datagrid. When I originally fill the dataset, the data is loaded into dataset.tables(0). (dataset.tables(0).rows.count = 8) Then, if a row...
3
by: Stanav | last post by:
Hello all, I'm developing a web application using VB.Net 2003 and Framework 1.1. This application queries an AS/400 database. I'm using the IBM OleDb provider that came with IBM Client Access for...
10
by: dauphian | last post by:
Hello, I am new to .net and am trying to build a report application that queries 4 different tables based on a id, and I need to return them in the same table for easy viewing. Basically, I...
2
by: MDB | last post by:
Hello All, I have a data grid that I fill using a dataset. The results of the query has around 15 columns and 500 rows (and growing). The reason I am using the datagrid is so the end users can...
5
by: Monty M. | last post by:
Hello; I was wondering if anyone can assist me with this problem. Here are the tools I am using: Language: C# Database: MS SQL Server 2000 Application: Visual Studio 2005 1. I have a...
2
by: slinky | last post by:
I'm getting a error when I open my . aspx in my browser... line 34: da.Fill(ds, "Assets") Here's the error and my entire code for this .aspx.vb is below that ... I need some clues as to what is...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.