M
Michael Maes
Hello,
I want to select an image with the OpenFileDialog and set it to a field in a datatable. Calling the DataSet.Update() should save the image (among other changes in the DataSet) to the DataSource (SQL Server 2000 sp3).
The thing is: I get it to work if I do it directly with SQL, but if I have the DataSet.Update() do it, I get an error when the when the DataSet get Re-loaded (and I move to the Updated record):
System.ArgumentException: Invalid parameter used.
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement)
at System.Drawing.Image.FromStream(Stream stream)
at ........
This is the code I use:
' Save the image to the Database using SQL
With Me.picProduct_Thumbnail
.Image = Image.FromFile(OpenFileDialog1.FileName)
.SizeMode = PictureBoxSizeMode.CenterImage
End With
Dim mStream As New System.IO.MemoryStream
picProduct_Thumbnail.Image.Save(mStream, picProduct_Thumbnail.Image.RawFormat)
Dim bytImage() As Byte = mStream.GetBuffer
mStream.Close()
Dim sProductID As String = Me.DsPicture1.tblProducts(Me.cmPic.Position).productID
Dim strSQL As String = _
"UPDATE tblProducts SET thumbnail = @thumbnail" & _
" WHERE ([productID] = '" & sProductID & "' AND [companyID] = 1)" ' & Session.CompanyID & ")"
Dim cmd As New SqlCommand(strSQL, Adapters.sdcStegoBase)
With cmd
.Parameters.Add(New SqlParameter("@thumbnail", _
SqlDbType.Image)).Value = bytImage
End With
Adapters.sdcStegoBase.Open()
cmd.ExecuteNonQuery()
Adapters.sdcStegoBase.Close()
' Save the image to the Database using Dataset.Update()
Me.DsPicture1.tblProducts.Rows(cmPic.Position)(Me.DsPicture1.tblProducts.thumbnailColumn.ToString) = bytImage
Me.SqlDataAdapter1.Update(Me.DsPicture1)
Me.DsPicture1.AcceptChanges()
a.. I use Bitmaps for testing
b.. thumbnail has an Image DataType in the Database and base64Binary in the Schema
c.. I'm using vb 2003
I've looked at all the postings I've found (many of Cor) but I "simply do not see it" :-( - My brains are boiled I guess.....
Thanks for any help,
Michael
I want to select an image with the OpenFileDialog and set it to a field in a datatable. Calling the DataSet.Update() should save the image (among other changes in the DataSet) to the DataSource (SQL Server 2000 sp3).
The thing is: I get it to work if I do it directly with SQL, but if I have the DataSet.Update() do it, I get an error when the when the DataSet get Re-loaded (and I move to the Updated record):
System.ArgumentException: Invalid parameter used.
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement)
at System.Drawing.Image.FromStream(Stream stream)
at ........
This is the code I use:
' Save the image to the Database using SQL
With Me.picProduct_Thumbnail
.Image = Image.FromFile(OpenFileDialog1.FileName)
.SizeMode = PictureBoxSizeMode.CenterImage
End With
Dim mStream As New System.IO.MemoryStream
picProduct_Thumbnail.Image.Save(mStream, picProduct_Thumbnail.Image.RawFormat)
Dim bytImage() As Byte = mStream.GetBuffer
mStream.Close()
Dim sProductID As String = Me.DsPicture1.tblProducts(Me.cmPic.Position).productID
Dim strSQL As String = _
"UPDATE tblProducts SET thumbnail = @thumbnail" & _
" WHERE ([productID] = '" & sProductID & "' AND [companyID] = 1)" ' & Session.CompanyID & ")"
Dim cmd As New SqlCommand(strSQL, Adapters.sdcStegoBase)
With cmd
.Parameters.Add(New SqlParameter("@thumbnail", _
SqlDbType.Image)).Value = bytImage
End With
Adapters.sdcStegoBase.Open()
cmd.ExecuteNonQuery()
Adapters.sdcStegoBase.Close()
' Save the image to the Database using Dataset.Update()
Me.DsPicture1.tblProducts.Rows(cmPic.Position)(Me.DsPicture1.tblProducts.thumbnailColumn.ToString) = bytImage
Me.SqlDataAdapter1.Update(Me.DsPicture1)
Me.DsPicture1.AcceptChanges()
a.. I use Bitmaps for testing
b.. thumbnail has an Image DataType in the Database and base64Binary in the Schema
c.. I'm using vb 2003
I've looked at all the postings I've found (many of Cor) but I "simply do not see it" :-( - My brains are boiled I guess.....
Thanks for any help,
Michael