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
snappy3273Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tpwellsCommented:
add

 cmdGetFile.Parameters.Add("@Attachment_ID")

before

 cmdGetFile.Parameters("@Attachment_ID").Value = Request("AttachmentID").ToString


it may have to have a value so may have to use this line instead and just replace your previous line

 cmdGetFile.Parameters.Add("@Attachment_ID",Request("AttachmentID").ToString)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
snappy3273Author Commented:
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
0
prajeebkumarCommented:
is the Nullref exception thrown coz you don't have "AttachmentID" in Request object?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.