473,404 Members | 2,195 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,404 software developers and data experts.

Using two stored procs instead of two queries?

Roy
Hey all,
Here's a small VB codeblock that connects to a database and uses 2 SQL
queries then forms a relation for a master/detail view on the aspx side:

Private Sub Binddata(ByVal name As String)

Dim myconn As New
SqlConnection("server=localhost;uid=ser;pwd=none;d atabase=et")

Dim mycom As New SqlCommand("select * from tbl1;select * from tbl2",
myconn)

myconn.Open()
Dim newadp As New SqlDataAdapter(mycom)
Dim newds As New DataSet
newadp.Fill(newds)
newds.Relations.Add("nested", newds.Tables(0).Columns("bookingnum"),
newds.Tables(1).Columns("bookingnum"))

main_list.DataSource = newds.Tables(0).DefaultView
myconn.Close()
main_list.DataBind()

End Sub
Now, my question to the group mind is how can I substitute 2 Stored
Procedures in place of those two queries above? This doesn't work,
though I would think it would:

Private Sub Binddata(ByVal name As String)
Dim myconn As New
SqlConnection("server=localhost;uid=user;pwd=none; database=et")

Dim mycom As New
SqlCommand("et.dbo.user_data_top;et.dbo.user_data_ nested", myconn)

With mycom
..CommandType = CommandType.StoredProcedure
..Parameters.Add(New SqlParameter("@name", SqlDbType.NVarChar, 12)).Value
= name
End With

myconn.Open()
Dim newadp As New SqlDataAdapter(mycom)
Dim newds As New DataSet
newadp.Fill(newds)
newds.Relations.Add("nested", newds.Tables(0).Columns("bookingnum"),
newds.Tables(1).Columns("bookingnum"))
main_list.DataSource = newds.Tables(0).DefaultView

myconn.Close()
main_list.DataBind()
End Sub

*** Sent via Developersdex http://www.developersdex.com ***
Jan 27 '06 #1
2 1579
I imagine you would have to keep the command type as just text, and do
something like 'exec mysproc1; exec mysproc2' to actually run the stored
procedures.

"Roy" <SP*******@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hey all,
Here's a small VB codeblock that connects to a database and uses 2 SQL
queries then forms a relation for a master/detail view on the aspx side:

Private Sub Binddata(ByVal name As String)

Dim myconn As New
SqlConnection("server=localhost;uid=ser;pwd=none;d atabase=et")

Dim mycom As New SqlCommand("select * from tbl1;select * from tbl2",
myconn)

myconn.Open()
Dim newadp As New SqlDataAdapter(mycom)
Dim newds As New DataSet
newadp.Fill(newds)
newds.Relations.Add("nested", newds.Tables(0).Columns("bookingnum"),
newds.Tables(1).Columns("bookingnum"))

main_list.DataSource = newds.Tables(0).DefaultView
myconn.Close()
main_list.DataBind()

End Sub
Now, my question to the group mind is how can I substitute 2 Stored
Procedures in place of those two queries above? This doesn't work,
though I would think it would:

Private Sub Binddata(ByVal name As String)
Dim myconn As New
SqlConnection("server=localhost;uid=user;pwd=none; database=et")

Dim mycom As New
SqlCommand("et.dbo.user_data_top;et.dbo.user_data_ nested", myconn)

With mycom
CommandType = CommandType.StoredProcedure
Parameters.Add(New SqlParameter("@name", SqlDbType.NVarChar, 12)).Value
= name
End With

myconn.Open()
Dim newadp As New SqlDataAdapter(mycom)
Dim newds As New DataSet
newadp.Fill(newds)
newds.Relations.Add("nested", newds.Tables(0).Columns("bookingnum"),
newds.Tables(1).Columns("bookingnum"))
main_list.DataSource = newds.Tables(0).DefaultView

myconn.Close()
main_list.DataBind()
End Sub

*** Sent via Developersdex http://www.developersdex.com ***

Jan 27 '06 #2
Hello Roy,

I might be tempted to put both queries into one stored procedure, fill the
dataset, and then establish the relationship (putting both queries into the
stored proc would cut down on a round trip). Something like this (sorry it's
C#, but it's what I know):

Store Proc:
CREATE PROCEDURE dbo.CombinedQuery
(
@Parm1 int;
@Parm2 int;
)
AS
SET NOCOUNT ON
SELECT * FROM Table1 WHERE col > @Parm1
SELECT * FROM Table2 WHERE col < @Parm2
RETURN
=-=-=-=-=-=-=-
Then fill the dataset and add the relationship:
public DataSet SelectCombinedQuery()
{
ConnectionStringSettings connectionStringSettings =
ConfigurationManager.ConnectionStrings["MyConnectionString"];

// Create Instance of Connection and Command Object
SqlConnection sqlConn = new
SqlConnection(connectionStringSettings.ConnectionS tring);
SqlCommand sqlCommand = new SqlCommand("CombinedQuerry", sqlConn);

sqlCommand.Parameters.AddWithValue("@Parm1", parm1);
sqlCommand.Parameters.AddWithValue("@Parm2", parm2);

// Mark the Command as a SPROC
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlConn.Open();

SqlDataAdapter da = new SqlDataAdapter(sqlCommand);
DataSet ds = new DataSet();

da.Fill(ds);

ds.Tables[0].TableName = "Table1";
ds.Tables[1].TableName = "Table2";

ds.Relations.Add("Table1Table2", ds.Tables["Table1"].Columns["ID1"],
ds.Tables["Table2"].Columns["ID1"]);
return ds;
}

--
The stored procedure will return 2 rowsets in the two tables in the dataset
when you call fill on the dataadapter. On return from the stored proc call,
you name the tables and then add the relationship between them. I know I've
changed your question a bit but hope this helps.

enjoy - brians
http://www.limbertech.com
"Roy" wrote:
Hey all,
Here's a small VB codeblock that connects to a database and uses 2 SQL
queries then forms a relation for a master/detail view on the aspx side:

Private Sub Binddata(ByVal name As String)

Dim myconn As New
SqlConnection("server=localhost;uid=ser;pwd=none;d atabase=et")

Dim mycom As New SqlCommand("select * from tbl1;select * from tbl2",
myconn)

myconn.Open()
Dim newadp As New SqlDataAdapter(mycom)
Dim newds As New DataSet
newadp.Fill(newds)
newds.Relations.Add("nested", newds.Tables(0).Columns("bookingnum"),
newds.Tables(1).Columns("bookingnum"))

main_list.DataSource = newds.Tables(0).DefaultView
myconn.Close()
main_list.DataBind()

End Sub
Now, my question to the group mind is how can I substitute 2 Stored
Procedures in place of those two queries above? This doesn't work,
though I would think it would:

Private Sub Binddata(ByVal name As String)
Dim myconn As New
SqlConnection("server=localhost;uid=user;pwd=none; database=et")

Dim mycom As New
SqlCommand("et.dbo.user_data_top;et.dbo.user_data_ nested", myconn)

With mycom
.CommandType = CommandType.StoredProcedure
.Parameters.Add(New SqlParameter("@name", SqlDbType.NVarChar, 12)).Value
= name
End With

myconn.Open()
Dim newadp As New SqlDataAdapter(mycom)
Dim newds As New DataSet
newadp.Fill(newds)
newds.Relations.Add("nested", newds.Tables(0).Columns("bookingnum"),
newds.Tables(1).Columns("bookingnum"))
main_list.DataSource = newds.Tables(0).DefaultView

myconn.Close()
main_list.DataBind()
End Sub

*** Sent via Developersdex http://www.developersdex.com ***

Jan 27 '06 #3

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

Similar topics

4
by: Roy | last post by:
Greetings, I've been avoiding it for so long, but like an evil wraith it always returns to haunt me. The bane of my existence, it is... bidirectional sorting!!! Checked out previous posts and...
1
by: kentk | last post by:
Is there a difference in how SQL Server 7 and SQL 2000 processes SQL passed from a program by an ADO command object. Reason I ask is I rewrote a couple applications a couple years ago were the SQL...
15
by: Burt | last post by:
I'm a stored proc guy, but a lot of people at my company use inline sql in their apps, sometimes putting the sql in a text file, sometimes hardcoding it. They don't see much benefit from procs, and...
9
by: Ronald S. Cook | last post by:
What do you guys think of abandoning stored procedures and writhing the SQL in code? I'm a little new to the debate and not sure I totally understand. From my command object, I can just select...
4
by: Andy B | last post by:
Where would probably be the best place for queries to the database? in the db as stroed procs or in the dataSet.
2
by: Andy B | last post by:
Is there an easy way to convert tableAdaptor queries into stored procs without messing up the dataTables in the dataSet or losing the queries themselves?
1
by: Andy B | last post by:
Hi... I have a dataset with queries in them. I want to switch out the queries for stored procs. When I tried to redefine the select query as a stored proc, I get this error: Cannot remove...
8
by: Frank Calahan | last post by:
I've been looking at LINQ and it seems very nice to be able to make queries in code, but I use stored procs for efficiency. If LINQ to SQL only works with SQL Server and stored procs are more...
5
by: Bogdan | last post by:
Hi, I have a stored procedure that uses JOINs to return columns from multiple tables. I also have another stored proc that that takes a series of params and updates multiple tables. I used the...
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
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.