SQL中的存储过程未设置为对象错误vb.net的实例

时间:2015-03-16 16:36:35

标签: asp.net vb.net stored-procedures ssms

当尝试调用并运行存储在vb.net中的sql server management studio中的存储过程时,我收到一条错误消息,指出我的存储过程未设置为对象的实例。我已经测试过,我的存储过程在sql中执行,在我的数据库类中有一个运行存储过程(没有参数)的子程序,并调用该过程并使用存储过程名称传递它。

以下是我的数据库类中两个subs的代码:

Public Sub RunProcedure(ByVal strName As String)

    ' CREATES INSTANCES OF THE CONNECTION AND COMMAND OBJECT
    Dim objConnection As New SqlConnection(mstrConnection)
    ' Tell SQL server the name of the stored procedure you will be executing
    Dim mdbDataAdapter As New SqlDataAdapter(strName, objConnection)
    Try
        ' SETS THE COMMAND TYPE TO "STORED PROCEDURE"
        mdbDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure
        ' clear dataset
        Me.mDatasetCustomer.Clear()
        ' OPEN CONNECTION AND FILL DATASET
        mdbDataAdapter.Fill(mDatasetCustomer, "tblCustomers")
        ' copy dataset to dataview
        mMyView.Table = mDatasetCustomer.Tables("tblCustomers")
    Catch ex As Exception
        Throw New Exception("stored procedure is " & strName.ToString & " error is " & ex.Message)
    End Try
End Sub

Public Sub GetAllUsingSP()
    ' purpose: get all customer records with stored procedure
    ' inputs:  none directly
    ' returns: all customer records
    RunProcedure("usp_Customers_Get_All")
End Sub

以下是我在实际网络表单中的代码,我将其称为sub:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        'get all customers from db
        DB.GetAllUsingSP()
        'set up gridview
        gvCustomers.DataSource = DB.CustDataset.Tables("tblCustomers")
        'bind data
        gvCustomers.DataBind()
    End Sub

如果有人能帮我理解问题所在,我会非常感激!

0 个答案:

没有答案