奇怪的'参数未提供'错误

时间:2014-01-26 21:47:27

标签: asp.net

好的,我有这个简单的存储过程:

 CREATE PROCEDURE dbo.spLoadRFPIDs
    -- Add the parameters for the stored procedure here
    @ClientID VARCHAR(10),
    @BidYear VARCHAR(20)
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    SELECT
        -- these are the property and Bid specifics.. the RFPID the Propcode etc..
        ID_RFP AS 'RFP ID',
        PropCode AS 'Property Code',
        Chain_Parent AS 'Parent Chain',
        PropName AS 'Property Name',
        PropAdd1 AS 'Property Address',
        --ALl the GDS Codes
        SabreCC AS 'Sabre CC',
        SabrePC AS 'Sabre PC',
        ApolloPC AS 'Apollo',
        AmadeusPC AS 'Amadeus',
        WorldspanPC AS 'Worldspan'

        --This is our preferred, company View
        FROM port_prfh_co prch

    WHERE
        prch.AcctCode = @ClientID -- We always use a clientid to identify which client we are using
        and prch.BidYear = @BidYear -- Each client has a BidYear all their Bids are associated with. some of our clients are still on the 2013 year and have not started 2014 yet.
        and prch.Accept_Status = 'Accept' 
END

在我的代码背后,我称之为(就像我说的那样简单)

Public Function Load(ByVal client_id As String, ByVal year As String) As DataTable
    Using conn As New SqlConnection(SqlConn.GetConnectionString("ProLodgic"))
        Using cmd As New SqlCommand()
            With cmd
                .CommandType = CommandType.StoredProcedure
                .CommandText = "spLoadRFPIDs"
                .Parameters.AddWithValue("@ClientID", client_id)
                .Parameters.AddWithValue("@BidYear", year)
                .Connection = conn
            End With

            SqlConn.HandleConnection(conn, False)

            Using ad As New SqlDataAdapter(cmd)
                ad.SelectCommand = New SqlCommand(cmd.CommandText, conn)
                Dim table As New DataTable()
                Try

                    ad.Fill(table)
                    Return table
                Catch ex As Exception
                    ErrorMessage.Text = ex.Message
                    Return Nothing
                End Try
            End Using
        End Using
    End Using
End Function

Protected Sub RadGrid1_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
    TryCast(sender, RadGrid).DataSource = Load("bloomberg", "2014")
End Sub

但是当我加载页面时,我收到一个错误,告诉我@ClientID没有提供,但是你可以清楚地看到我提供它,所以我在这里缺少什么?

1 个答案:

答案 0 :(得分:0)

您正在为SqlCommand的属性SelectCommand分配新的SqlDataAdapter 当然,这个新的SqlCommand没有参数,也没有类型StoredProcedure

但是SqlCommand的构造函数中使用的SqlDataAdapter会自动指定为SqlDataAdapter的SelectCommand

  Using ad As New SqlDataAdapter(cmd)
      ' just comment the following line '
      ' ad.SelectCommand = New SqlCommand(cmd.CommandText, conn) '