N
Neo Geshel
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.
**********************************************************************
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.
**********************************************************************