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

1 connection- 2 result tables

Hi there,

I am very sorry for my not perfect English.

I've got very simple question. Is it possible to have stored procedure with
2 result tables and then from my application to refer to this tables by ado.

Something likes that:

Select * from aaa

Select * from bbb

And then in my application

SqlDataAdapter adapter=new SqlDataAdapter();

DataSet MyDataSet=new DataSet();

adapter.Fill(MyDataSet, "aaa");

adapter.Fill(MyDataSet, "bbb");

Basically I want to receive with 1 connection to the database 2 tables.

If is possible haw I can do it,

And if is not possible is there any other way I can do it?

Thanks in advance
Nov 19 '05 #1
4 1046
Yes.

You would then refer to it using syntax such as myDataset.Tables[0] or
myDataset.Tables[1].

The tables are just indexed in the table collection and can be accessed.

"Avon" <mi*********@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
Hi there,

I am very sorry for my not perfect English.

I've got very simple question. Is it possible to have stored procedure
with 2 result tables and then from my application to refer to this tables
by ado.

Something likes that:

Select * from aaa

Select * from bbb

And then in my application

SqlDataAdapter adapter=new SqlDataAdapter();

DataSet MyDataSet=new DataSet();

adapter.Fill(MyDataSet, "aaa");

adapter.Fill(MyDataSet, "bbb");

Basically I want to receive with 1 connection to the database 2 tables.

If is possible haw I can do it,

And if is not possible is there any other way I can do it?

Thanks in advance

Nov 19 '05 #2
Hello Dear Avon,

Yes You can have a stored procedure with 2 SQL Select Statement.
I will show you how you can also retreive 2 SQL Select Statements in one
single Query.

It goes like this.

Create a connection string

const string dsn="server=(local);trusted_connection=yes;databas e=pubs";

Using(SqlConnection conn = new SqlConnection(dsn);

Using(SqlCommand cmd = new SqlCommand(SELECT * FROM Authors;SELECT * FROM
Publishers", conn));

//here you can give two (2) SQL Statements with a semicolon (;) in-between
like above.

SqlDataReader dr = cmd.ExecuteReader();
do
{
while (dr.read())
{
Console.Writeline(" {0} {1}", dr[1], dr[2]);
}

}while(reader.NextResult[1])
}

************************************************** ************************************************** ********************

You can also fill the DataSet with 2 Tables like below

Create a connection string

const string dsn="server=(local);trusted_connection=yes;databas e=pubs";

Using(SqlConnection conn = new SqlConnection(dsn);

SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Authors;SELECT * FROM
Publishers", conn);
then you can fill the DataSet like this
=======================
DataSet ds = new DataSet();

da.Fill(ds,"Authors");

//The Table Name "Authors" is assigned to the First (1st) DataTable. You
have to Specifically Assign the Table Name for the Second (2nd) DataTable
like below

ds.Tables[1].TableName="Publishers"

you can user the DataTable by refereing either their Ordinal Number or Name
of the Table like below

ds.Tables["Authors"]
or
ds.Tables[0]

AND / OR

ds.Tables["Publishers"]
or
ds.Tables[1]

For anything and everything please let me know

bye
Venkat_KL
Nov 19 '05 #3
Hi dear Avon,

you can also read these two pages by clicking the respective URLs

Inserting relational data using DataSet and DataAdapter
====================================

http://www.codeproject.com/cs/databa...&select=937255
DataSet Class
=========
http://msdn.microsoft.com/library/de...classtopic.asp

bye
Venkat_KL
Nov 19 '05 #4
Thanks a lot friends!

"Avon" <mi*********@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
Hi there,

I am very sorry for my not perfect English.

I've got very simple question. Is it possible to have stored procedure
with 2 result tables and then from my application to refer to this tables
by ado.

Something likes that:

Select * from aaa

Select * from bbb

And then in my application

SqlDataAdapter adapter=new SqlDataAdapter();

DataSet MyDataSet=new DataSet();

adapter.Fill(MyDataSet, "aaa");

adapter.Fill(MyDataSet, "bbb");

Basically I want to receive with 1 connection to the database 2 tables.

If is possible haw I can do it,

And if is not possible is there any other way I can do it?

Thanks in advance

Nov 19 '05 #5

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

Similar topics

3
by: G-Fit | last post by:
Hello group, I have several servers hosting SQL databases. On each of them, I have several databases. All those databases have the same structure (even those on different servers), only the data...
11
by: pradeep_TP | last post by:
Hi all, I have a few questions that I have been wanting to ask for long. These are all related to ADO.net and specifically to conenction to database. 1) If I have opened a connection to a...
6
by: Chris Szabo | last post by:
I've created a data access layer for a .NET web application. I'm using C# and framework 1.1. I'm getting an error from time to time when I close a connection saying: ...
18
by: Rob Nicholson | last post by:
We're getting an occasional occurrence of the following error when two users try and open the same record in our ASP.NET app: "There is already an open DataReader associated with this Connection...
35
by: Eric Sabine | last post by:
In my Finally block, I was using cn.close (where cn is an ADO.NET connection object, SQLConnection to be exact) and then I came across the following in some microsoft code. If Not cn Is Nothing...
3
by: Martin B | last post by:
Hallo! I'm working with C# .NET 2.0, implementing Client/Server Applications which are connecting via Network to SQL-Server or Oracle Databases. To stay independent from the underlaying Database...
20
by: fniles | last post by:
I am using VS2003 and connecting to MS Access database. When using a connection pooling (every time I open the OLEDBCONNECTION I use the exact matching connection string), 1. how can I know how...
3
by: fniles | last post by:
In the Windows application (using VB.NET 2005) I use connection pooling like the following: In the main form load I open a connection using a connection string that I stored in a global variable...
0
by: Robert Avery | last post by:
In VBA/VB6, I had a class (incomplete sample below) that watched and displayed for the user all connection events, so that I could easily see what SQL was taking a long time, and when it freezes, I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.