Image Upload Irrational Error - "not declared" error despite identicalcode!!!

Discussion in 'ASP .Net' started by Neo Geshel, Jun 13, 2005.

  1. Neo Geshel

    Neo Geshel Guest

    I am trying to upload images to an access db using a DataGrid. The code
    inside the INSERT sub is identical to almost everything else I've seen
    on the net, but it still won't work. The compiler seems to not recognize
    that the add_CarShowGalleryPhoto is referring to a form field with a
    type of "file". How do I modify the code so that it works??

    Sub dgCarShowGalleryPhotos_Insert(sender As Object, e As
    DataGridCommandEventArgs)
    If e.CommandName = "Insert" Then
    If Not add_CarShowGalleryPhoto.PostedFile Is Nothing Then
    If add_CarShowGalleryPhoto.PostedFile.ContentLength > 0 And
    add_CarShowGalleryPhoto.PostedFile.ContentType = "image/jpeg" Then
    Dim imgStream As Stream = add_CarShowGalleryPhoto.PostedFile.InputStream()
    If add_CarShowGalleryPhoto.PostedFile.Width > 640 Or
    add_CarShowGalleryPhoto.PostedFile.Height > 640 Then
    Dim imgbin(createThumbnail(imgStream, 640, 640)) as Byte
    Else
    Dim imgLen As Int32 = add_CarShowGalleryPhoto.PostedFile.ContentLength
    Dim imgBinaryData(imgLen) as Byte
    Dim n As Int32 = imgStream.Read(imgBinaryData, 0, imgLen)
    Dim imgBin(imgBinaryData) as Byte
    End If
    Dim strComment As String =
    CType(e.Item.FindControl("add_CarShowGalleryComment"),
    TextBox).Text.Replace("'","’")
    Dim strSQL As String = "INSERT INTO [tblCarShowGalleryPhotos]
    (CarShowGalleryYearID, Image, Comment) VALUES (" & Session("IDHolder") &
    ", @Image, @Comment)"
    Dim objConn as New
    OleDbConnection(ConfigurationSettings.AppSettings("strConn"))
    objConn.Open()
    Dim myCommand as OleDbCommand = new OleDbCommand(strSQL, objConn)
    myCommand.CommandType = CommandType.Text
    Dim parameterImage as OleDbParameter = new OleDbParameter("@Image",
    OleDbType.LongVarBinary)
    parameterImage.Value = imgBin
    myCommand.Parameters.Add(parameterImage)
    Dim parameterComment as OleDbParameter = new OleDbParameter("@Comment",
    OleDbType.LongVarWChar)
    parameterComment.Value = strComment
    myCommand.Parameters.Add(parameterComment)
    myCommand.ExecuteNonQuery()
    objConn.Close()
    dgCarShowGalleryPhotos.EditItemIndex = -1
    BindData()
    End If
    End If
    End If
    End Sub



    TIA
    ...Geshel
    --
    **********************************************************************
    My reply-to is an automatically monitored spam honeypot. Do not use it
    unless you want to be blacklisted by SpamCop. Please reply to my first
    name at my last name dot org.
    **********************************************************************
     
    Neo Geshel, Jun 13, 2005
    #1
    1. Advertising

  2. RE: Image Upload Irrational Error - "not declared" error despite ident

    That is because you need to declare it within the codebehind class (not
    inside any method). Look at your othercontrols: they will all be declared
    like that. Also be sure runnat=server is on the control.

    "Neo Geshel" wrote:

    > I am trying to upload images to an access db using a DataGrid. The code
    > inside the INSERT sub is identical to almost everything else I've seen
    > on the net, but it still won't work. The compiler seems to not recognize
    > that the add_CarShowGalleryPhoto is referring to a form field with a
    > type of "file". How do I modify the code so that it works??
    >
    > Sub dgCarShowGalleryPhotos_Insert(sender As Object, e As
    > DataGridCommandEventArgs)
    > If e.CommandName = "Insert" Then
    > If Not add_CarShowGalleryPhoto.PostedFile Is Nothing Then
    > If add_CarShowGalleryPhoto.PostedFile.ContentLength > 0 And
    > add_CarShowGalleryPhoto.PostedFile.ContentType = "image/jpeg" Then
    > Dim imgStream As Stream = add_CarShowGalleryPhoto.PostedFile.InputStream()
    > If add_CarShowGalleryPhoto.PostedFile.Width > 640 Or
    > add_CarShowGalleryPhoto.PostedFile.Height > 640 Then
    > Dim imgbin(createThumbnail(imgStream, 640, 640)) as Byte
    > Else
    > Dim imgLen As Int32 = add_CarShowGalleryPhoto.PostedFile.ContentLength
    > Dim imgBinaryData(imgLen) as Byte
    > Dim n As Int32 = imgStream.Read(imgBinaryData, 0, imgLen)
    > Dim imgBin(imgBinaryData) as Byte
    > End If
    > Dim strComment As String =
    > CType(e.Item.FindControl("add_CarShowGalleryComment"),
    > TextBox).Text.Replace("'","’")
    > Dim strSQL As String = "INSERT INTO [tblCarShowGalleryPhotos]
    > (CarShowGalleryYearID, Image, Comment) VALUES (" & Session("IDHolder") &
    > ", @Image, @Comment)"
    > Dim objConn as New
    > OleDbConnection(ConfigurationSettings.AppSettings("strConn"))
    > objConn.Open()
    > Dim myCommand as OleDbCommand = new OleDbCommand(strSQL, objConn)
    > myCommand.CommandType = CommandType.Text
    > Dim parameterImage as OleDbParameter = new OleDbParameter("@Image",
    > OleDbType.LongVarBinary)
    > parameterImage.Value = imgBin
    > myCommand.Parameters.Add(parameterImage)
    > Dim parameterComment as OleDbParameter = new OleDbParameter("@Comment",
    > OleDbType.LongVarWChar)
    > parameterComment.Value = strComment
    > myCommand.Parameters.Add(parameterComment)
    > myCommand.ExecuteNonQuery()
    > objConn.Close()
    > dgCarShowGalleryPhotos.EditItemIndex = -1
    > BindData()
    > End If
    > End If
    > End If
    > End Sub
    >
    >
    >
    > TIA
    > ...Geshel
    > --
    > **********************************************************************
    > My reply-to is an automatically monitored spam honeypot. Do not use it
    > unless you want to be blacklisted by SpamCop. Please reply to my first
    > name at my last name dot org.
    > **********************************************************************
    >
     
    =?Utf-8?B?SmFzb24gTCBMaW5k?=, Jun 13, 2005
    #2
    1. Advertising

  3. Neo Geshel

    Neo Geshel Guest

    Re: Image Upload Irrational Error - "not declared" error despiteident

    Jason L Lind wrote:
    > "Neo Geshel" wrote:
    >>I am trying to upload images to an access db using a DataGrid. The code
    >>inside the INSERT sub is identical to almost everything else I've seen
    >>on the net, but it still won't work. The compiler seems to not recognize
    >>that the add_CarShowGalleryPhoto is referring to a form field with a
    >>type of "file". How do I modify the code so that it works??
    >>
    >>Sub dgCarShowGalleryPhotos_Insert(sender As Object, e As
    >>DataGridCommandEventArgs)
    >> If e.CommandName = "Insert" Then
    >> If Not add_CarShowGalleryPhoto.PostedFile Is Nothing Then
    >> If add_CarShowGalleryPhoto.PostedFile.ContentLength > 0 And
    >>add_CarShowGalleryPhoto.PostedFile.ContentType = "image/jpeg" Then
    >> Dim imgStream As Stream = add_CarShowGalleryPhoto.PostedFile.InputStream()
    >> If add_CarShowGalleryPhoto.PostedFile.Width > 640 Or
    >>add_CarShowGalleryPhoto.PostedFile.Height > 640 Then
    >> Dim imgbin(createThumbnail(imgStream, 640, 640)) as Byte
    >> Else
    >> Dim imgLen As Int32 = add_CarShowGalleryPhoto.PostedFile.ContentLength
    >> Dim imgBinaryData(imgLen) as Byte
    >> Dim n As Int32 = imgStream.Read(imgBinaryData, 0, imgLen)
    >> Dim imgBin(imgBinaryData) as Byte
    >> End If
    >> Dim strComment As String =
    >>CType(e.Item.FindControl("add_CarShowGalleryComment"),
    >>TextBox).Text.Replace("'","’")
    >> Dim strSQL As String = "INSERT INTO [tblCarShowGalleryPhotos]
    >>(CarShowGalleryYearID, Image, Comment) VALUES (" & Session("IDHolder") &
    >>", @Image, @Comment)"
    >> Dim objConn as New
    >>OleDbConnection(ConfigurationSettings.AppSettings("strConn"))
    >> objConn.Open()
    >> Dim myCommand as OleDbCommand = new OleDbCommand(strSQL, objConn)
    >> myCommand.CommandType = CommandType.Text
    >> Dim parameterImage as OleDbParameter = new OleDbParameter("@Image",
    >>OleDbType.LongVarBinary)
    >> parameterImage.Value = imgBin
    >> myCommand.Parameters.Add(parameterImage)
    >> Dim parameterComment as OleDbParameter = new OleDbParameter("@Comment",
    >>OleDbType.LongVarWChar)
    >> parameterComment.Value = strComment
    >> myCommand.Parameters.Add(parameterComment)
    >> myCommand.ExecuteNonQuery()
    >> objConn.Close()
    >> dgCarShowGalleryPhotos.EditItemIndex = -1
    >> BindData()
    >> End If
    >> End If
    >> End If
    >>End Sub
    >>
    >>TIA
    >>...Geshel

    > That is because you need to declare it within the codebehind class (not
    > inside any method). Look at your othercontrols: they will all be declared
    > like that. Also be sure runnat=server is on the control.
    >


    Actually, I think I've got it working now. I'm not using code-behind at
    this time for simplicity. I'm not the most advanced at ASP.NET, so I'm
    keeping everything inline until it works.

    Turns out I needed to DIM the form field first (Dim imgContent as Object
    = e.Item.Cells(2).Controls(1)), and then use imgContent as a placeholder
    (imgContent.PostedFile...)

    Turns out quite a few web sites failed to display or mention this...
    hence my frustration.

    Thanks anyhow.
    ...Geshel
    --
    **********************************************************************
    My reply-to is an automatically monitored spam honeypot. Do not use it
    unless you want to be blacklisted by SpamCop. Please reply to my first
    name at my last name dot org.
    **********************************************************************
     
    Neo Geshel, Jun 14, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Carpe Diem
    Replies:
    3
    Views:
    7,188
    Carpe Diem
    Feb 23, 2004
  2. =?Utf-8?B?U2FtIEphY2tzb24=?=

    Form posting despite validation errors

    =?Utf-8?B?U2FtIEphY2tzb24=?=, Apr 5, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    377
    =?Utf-8?B?U2FtIEphY2tzb24=?=
    Apr 5, 2004
  3. =?Utf-8?B?TWFyayBQYXJ0ZXI=?=

    Form still being submitted despite being invalid

    =?Utf-8?B?TWFyayBQYXJ0ZXI=?=, Jul 25, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    611
  4. JohnZing

    declared or not declared ?

    JohnZing, Feb 5, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    1,595
    Jon Paal
    Feb 5, 2006
  5. Replies:
    1
    Views:
    371
    Mike Schilling
    Mar 2, 2005
Loading...

Share This Page