Link to home
Start Free TrialLog in
Avatar of MadIce
MadIce

asked on

Save Clipboard image to Sql Server Table

I copy a chart from Excel to the clipboard and now want to save to a table. Problem is changing the format. I'm trying to save to two different formats to see if it makes a difference. col DImage is a varbinary(max) type and XChart is image type. Just testing to see what works. When I try to copy the image to either field I get an error trying to copy to a byte type.  Does someone have a code example to convert the clipboard image to the right type?

Using VB.net 2005 with sql server 2005.

oChart.CopyPicture(Appearance:=Excel.XlPictureAppearance.xlScreen, Size:=Excel.XlPictureAppearance.xlScreen, Format:=Excel.XlCopyPictureFormat.xlBitmap)
 
                        Dim ClipImage As System.Drawing.Image
                        If My.Computer.Clipboard.ContainsImage() Then
                            ClipImage = My.Computer.Clipboard.GetImage
 
                        Else
                            MsgBox("No Images in ClipBoard")
                        End If
               
                        Dim row As DataRow
                        Dim intRCnt As Integer
                        intRCnt = 0
                        For Each row In dtDODICImages.Rows
                            If dtDImages.Rows(intRCnt).Item("DCD") = strDCD Then
                                dtDImages.Rows(intRCnt).Item("DImage") = ClipImage
                                dtDImages.Rows(intRCnt).Item("XChart") = ClipImage
                                Exit For
                            End If
                            intRCnt += 1
                        Next row

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of JackOfPH
JackOfPH
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MadIce
MadIce

ASKER

I thought I closed this. sorry for the delay. I didn't use exactly what you  put but it help me solve the issue. Thanks