Hi All,
im in the process of creating a mini auction in vb.net, so far i have deisgned the pages and now im beginning to code, but im stuck on the Fileupload of the image, this is the first time i have used a file upload so im looking for guidance is possible.
My SQL Column where i want to save the image is set up as a data type image but when i run the application i get this error "Operand type clash: nvarchar is incompatible with image"
My Code behind the BtnAuction Item
If ItemPicture.HasFile Then
Try
Dim FileName As String = Server.HtmlEncode(ItemPicture.FileName)
Dim Extension As String = System.IO.Path.GetExtension(FileName)
If (Extension.ToUpper = ".JPG") Or (Extension.ToUpper = ".GIF") Or (Extension.ToUpper = ".PNG") Then
Dim image_file As System.Drawing.Image = System.Drawing.Image.FromStream(ItemPicture.PostedFile.InputStream)
Dim image_height As Integer = image_file.Height
Dim image_width As Integer = image_file.Width
Dim max_height As Integer = 12011
Dim max_width As Integer = 160
image_height = (image_height * max_width) / image_width
image_width = max_width
If image_height > max_height Then
image_width = (image_width * max_height) / image_height
Else
End If
Dim BitMap_File As New Bitmap(image_file, image_width, image_height)
Dim Stream As New System.IO.MemoryStream
BitMap_File.Save(Stream, System.Drawing.Imaging.ImageFormat.Jpeg)
Stream.Position = 0
Dim data(Stream.Length) As Byte
Stream.Read(data, 0, Stream.Length)
Picture = BitMap_File
End If
Catch ex As Exception
End Try
End If
GlobalHash.Add("@spItemTitle", txtAuctionTitle.Text)
GlobalHash.Add("@spItemCondition", ddlCondition.SelectedValue)
GlobalHash.Add("@spStartingPrice", txtStartingPrice.Text)
GlobalHash.Add("@spItemStatus", status)
GlobalHash.Add("@spItemDescription", txtItemDescription.Text)
GlobalHash.Add("@spItemPicture", Picture)
GlobalHash.Add("@spItemOwner", UserID)
NewItem.InsertItem(GlobalHash)
End Sub
This is my function where i try and add the image aswell as the relevant information
Public Function InsertItem(ByVal ItemDetails As Hashtable) As Boolean
Dim SpParameter As DictionaryEntry
Dim cmd As New SqlCommand
cmd.CommandText = "NewItemToAuction"
cmd.CommandType = CommandType.StoredProcedure
For Each SpParameter In ItemDetails
cmd.Parameters.Add(New SqlParameter(SpParameter.Key, SpParameter.Value.ToString))
Next
Dim m_Connection As New SQLAccess
If m_Connection.EstablishConnection = True Then
cmd.Connection = m_Connection.SQLSVRConnection
cmd.ExecuteNonQuery()
Return True
Else
Return False
End If
End Function
If someone can help me i would highly appreciate it, as i have been banging my head on this for the past two days