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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dougancil
    Contributor
    • Apr 2010
    • 347

    #1

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

    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
  • yarbrough40
    Contributor
    • Jun 2009
    • 320

    #2
    Code:
    sql = "EXEC sp_1;EXEC sp_2;EXEC sp_3"

    Comment

    • dougancil
      Contributor
      • Apr 2010
      • 347

      #3
      yarbrough,

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

      Code:
       Dim oCmd2 As System.Data.SqlClient.SqlCommand
              Dim oDr2 As System.Data.SqlClient.SqlDataReader
              oCmd2 = New System.Data.SqlClient.SqlCommand
              Try
                  With oCmd2
                      .Connection = New System.Data.SqlClient.SqlConnection("Initial Catalog=mdr;Data Source=1xxxxx;uid=xxxxx;password=xxxxx")
                      .Connection.Open()
                      .CommandType = CommandType.StoredProcedure
                      .CommandText = "exec sp_opsum @payperiodstartdate = " + payperiodstartdate + ",@payperiodenddate=" + payperiodenddate + ";" + _
       "exec sp_opintcheck @payperiodstartdate = " + payperiodstartdate + ",@payperiodenddate=" + payperiodenddate + ";" + _
       "exec sp_opexceptsum @payperiodstartdate = " + payperiodstartdate + ",@payperiodenddate=" + payperiodenddate + ";" + _
       "exec sp_empsum @payperiodstartdate = " + payperiodstartdate + ",@payperiodenddate=" + payperiodenddate + ";" + _
       "exec sp_empexceptsum @payperiodstartdate = " + payperiodstartdate + ",@payperiodenddate=" + payperiodenddate + ";"
                      oDr2 = .ExecuteReader()
                      oCmd2.Connection.Close()
                  End With
              Catch ex As Exception
                  MessageBox.Show(ex.Message)
                  oCmd2.Connection.Close()
              End Try
              SPRun()
      which still doesnt work

      Comment

      Working...