Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1220
  • Last Modified:

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
0
snappy3273
Asked:
snappy3273
1 Solution
 
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
 
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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now