By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,688 Members | 1,738 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,688 IT Pros & Developers. It's quick & easy.

How to execute more than one stored procedure at a time?

100+
P: 347
I have a form that requires me to execute several stored procedures one after the other. I'm wondering how to do that in vb.net. I realize that I could just have one stored procedure with all of my queries in it, but for clarities sake, I want to keep them seperate.

Thank you

Doug
Jan 21 '11 #1
Share this Question
Share on Google+
2 Replies


yarbrough40
100+
P: 320
Expand|Select|Wrap|Line Numbers
  1. sql = "EXEC sp_1;EXEC sp_2;EXEC sp_3"
Jan 27 '11 #2

100+
P: 347
yarbrough,

I tried that and could never seem to get the sp's to execute. I have instead gone with this:

Expand|Select|Wrap|Line Numbers
  1.  Dim oCmd2 As System.Data.SqlClient.SqlCommand
  2.         Dim oDr2 As System.Data.SqlClient.SqlDataReader
  3.         oCmd2 = New System.Data.SqlClient.SqlCommand
  4.         Try
  5.             With oCmd2
  6.                 .Connection = New System.Data.SqlClient.SqlConnection("Initial Catalog=mdr;Data Source=1xxxxx;uid=xxxxx;password=xxxxx")
  7.                 .Connection.Open()
  8.                 .CommandType = CommandType.StoredProcedure
  9.                 .CommandText = "exec sp_opsum @payperiodstartdate = " + payperiodstartdate + ",@payperiodenddate=" + payperiodenddate + ";" + _
  10.  "exec sp_opintcheck @payperiodstartdate = " + payperiodstartdate + ",@payperiodenddate=" + payperiodenddate + ";" + _
  11.  "exec sp_opexceptsum @payperiodstartdate = " + payperiodstartdate + ",@payperiodenddate=" + payperiodenddate + ";" + _
  12.  "exec sp_empsum @payperiodstartdate = " + payperiodstartdate + ",@payperiodenddate=" + payperiodenddate + ";" + _
  13.  "exec sp_empexceptsum @payperiodstartdate = " + payperiodstartdate + ",@payperiodenddate=" + payperiodenddate + ";"
  14.                 oDr2 = .ExecuteReader()
  15.                 oCmd2.Connection.Close()
  16.             End With
  17.         Catch ex As Exception
  18.             MessageBox.Show(ex.Message)
  19.             oCmd2.Connection.Close()
  20.         End Try
  21.         SPRun()
  22.  
which still doesnt work
Jan 27 '11 #3

Post your reply

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