No mapping exists from object type System.Drawing.Bitmap to a known managed provider native type

  • Thread starter Thread starter Jeff07
  • Start date Start date
J

Jeff07

Guest
In this code I am trying to read photos from one table and saving them in another table, but receive the error above when trying to insert into a fpphotos table.

Any help would be appreciated.



Imports System.Data.SqlClient
Imports System.Data.SqlTypes

Private Sub TransferPhotos(ByVal Acct_No As String, ByVal Facct As String)

Dim DataSet2 As New DataSet

Dim strSelect = "SELECT facct, photo1, photo2 FROM appphotos " &
"WHERE facct = " & "'" & Acct_No & "'"

Dim DataAdapter2 As New SqlDataAdapter(strSelect, Connection1)

' Fill the dataSet object with data
DataAdapter2.Fill(DataSet2, "appphotos")

Dim intRow As Integer = DataSet2.Tables(0).Rows.Count

' Open connection
If Connection1.State = ConnectionState.Closed Then Connection1.Open()

Dim Command1 As New SqlCommand(strSelect, Connection1)
Dim SQLDataReader1 = Command1.ExecuteReader
Dim DataTable2 As New DataTable
Dim Image1, Image2 As Image

If intRow > 0 Then
DataTable2.Load(SQLDataReader1)
Dim row As DataRow = DataTable2.Rows(0)

' Photo 1
If IsDBNull(row("photo1")) Then
' Do nothing as photo is null value
Else
Dim MemoryStream1 As New IO.MemoryStream(CType(row("photo1"), Byte()))
Image1 = Image.FromStream(MemoryStream1)

If Not IsNothing(MemoryStream1) Then MemoryStream1.Dispose()
End If


' Photo 2
If IsDBNull(row("photo2")) Then
' Do nothing as photo is null value
Else
Dim MemoryStream2 As New IO.MemoryStream(CType(row("photo2"), Byte()))
Image2 = Image.FromStream(MemoryStream2)

If Not IsNothing(MemoryStream2) Then MemoryStream2.Dispose()

End If

End If


' ----------------

'Save photo in fpphoto table

Command1.CommandText = "INSERT INTO fpphotos " &
"(facct, photo_date1, photo1, photo_date2, photo2)" &
"VALUES(@facct, @photo_date1, @photo1, @photo_date2, @photo2)"

Command1.Parameters.AddWithValue("@facct", Facct)
Command1.Parameters.AddWithValue("@photo_date1", Date.Today)
Command1.Parameters.AddWithValue("@photo1", Image1)
Command1.Parameters.AddWithValue("@photo_date2", Date.Today)
Command1.Parameters.AddWithValue("@photo2", Image2)

Try
Command1.ExecuteNonQuery()

Catch SqlExceptionErr As SqlException
MessageBox.Show(SqlExceptionErr.Message)
IsError = True

End Try


' Close connection
If Connection1.State = ConnectionState.Open Then Connection1.Close()

' Dispose of objects
If Not IsNothing(Command1) Then Command1.Dispose()
If Not IsNothing(SQLDataReader1) Then SQLDataReader1.Close()
If Not IsNothing(DataTable2) Then DataTable2.Dispose()
If Not IsNothing(DataAdapter2) Then DataAdapter2.Dispose()

End Sub





ISV using VB.net and SQL Server

Continue reading...
 
Back
Top