如何在1 Sub上使用多个存储过程

时间:2014-03-18 02:39:29

标签: asp.net sql-server stored-procedures

我编写了一个代码来检索以显示来自使用ASP.NET的存储过程的数据

Private Sub AutoNumberVerification()
    Dim Conn As New SqlConnection(strConn.ToString)
    Dim cmd As New SqlCommand()
    Try
        cmd.Connection = Conn
        cmd.CommandType = CommandType.StoredProcedure
        Conn.Open()

        If (txtProducerID.Text.Trim.Length = 9) Then
            cmd.CommandText = "spProductCount"
            cmd.Parameters.AddWithValue("@ID", txtProducerID.Text)
        End If
        Dim da As New SqlDataAdapter(cmd)
        Dim dt As New DataTable()
        da.Fill(dt)
        Dim dr As SqlDataReader = cmd.ExecuteReader()
        dt.Load(dr)

        If (convertInteger(dt.Rows(0)("estbProducerID").ToString) > 0) Then
            cmd.CommandText = "spProductCount"
            rdoEstbProducerList.Items.FindByValue(convertInteger(dt.Rows(0)("estbProducerID"))).Selected = True

        End If

        cmd.CommandText = "spProductCount"
        TextBox11.Text = dt.Rows(0)("ALL").ToString
        TextBox4.Text = dt.Rows(0)("FOOD").ToString
        TextBox5.Text = dt.Rows(0)("DRINKS").ToString
        TextBox6.Text = dt.Rows(0)("TAILOR").ToString
        TextBox7.Text = dt.Rows(0)("USABLE").ToString
        TextBox8.Text = dt.Rows(0)("HERB").ToString


        cmd.CommandText = "spProductproveCounts"
        TextBox12.Text = dt.Rows(0)("REGISTERED").ToString
    Catch ex As Exception
        Response.Write("ERROR Load: " & ex.Message)
    Finally
        Conn.Close()
    End Try
End Sub

但它显示错误=" REGISTERED"不属于表

如何使用两个存储过程?

1 个答案:

答案 0 :(得分:0)

只是将cmd.CommandText设置为存储过程名称将不会执行它。每次更改CommandText

后,仍需要调用ExecuteReader