Link to home
Start Free TrialLog in
Avatar of snappy3273
snappy3273

asked on

An SqlParameter with ParameterName 'yada yada' is not contained by this SqlParameterCollection.

Hello everyone,
I've got a sub that's killing me here in that I've checked all names and it still bombs on the following line:
 
cmdGetFile.Parameters("@Attachment_ID").Value = Request("AttachmentID").ToString

An SqlParameter with ParameterName '@Attachment_ID' is not contained by this SqlParameterCollection.


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

        strGet = "SELECT FileSize, FileName, FileData, ContentType FROM tblAttachments WHERE (Attachment_ID = @Attachment_ID)"
        connectString = "Data Source=TXXPW320;Initial Catalog=ezscan;Integrated Security=True"
        Dim dbConn As New Data.SqlClient.SqlConnection(connectString)
        'setup command object
        Dim cmdGetFile As New Data.SqlClient.SqlCommand(strGet, dbConn)
        dbConn.Open()
        Dim dr As System.Data.SqlClient.SqlDataReader
        cmdGetFile.Parameters("@Attachment_ID").Value = Request("AttachmentID").ToString
        dbConn.Open()
        dr = cmdGetFile.ExecuteReader
        If dr.Read Then
            Response.ContentType = dr("ContentType").ToString
            Response.OutputStream.Write(CType(dr("FileData"), Byte()), 0, CInt(dr("FileSize")))
            Response.AddHeader("Content-Disposition", "attachment;filename=" + dr("FileName").ToString())
        Else
            mf.RW("File Not Found.")
        End If
    End Sub


Any suggestions would be greatly appreciated.
Thanks in advance,
S
ASKER CERTIFIED SOLUTION
Avatar of tpwells
tpwells

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of snappy3273
snappy3273

ASKER

When using this:
cmdGetFile.Parameters.AddWithValue("@Attachment_ID",Request("AttachmentID").ToString)

It rec i change "add" to "addwithvalue", once I ran it, it did this.
I get a NullReference exception: Object reference not set to an instance of an object.

I have no records in my DB though and am trying to get this upload script to work.
Thanks,
S
is the Nullref exception thrown coz you don't have "AttachmentID" in Request object?