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

Posted on 2006-03-30
Last Modified: 2011-09-20
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)
        Dim dr As System.Data.SqlClient.SqlDataReader
        cmdGetFile.Parameters("@Attachment_ID").Value = Request("AttachmentID").ToString
        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())
            mf.RW("File Not Found.")
        End If
    End Sub

Any suggestions would be greatly appreciated.
Thanks in advance,
Question by:snappy3273
    LVL 10

    Accepted Solution




     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


    Author Comment

    When using this:

    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.
    LVL 3

    Expert Comment

    is the Nullref exception thrown coz you don't have "AttachmentID" in Request object?

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now