Opening Image in Vb from SQL database
-
Hello friends, I stored an image from my front end(VB) into SQL database on a datatype image. Then how can I show that image in VB. Please help While loading it through recordset I get this '????' .
-
Hello friends, I stored an image from my front end(VB) into SQL database on a datatype image. Then how can I show that image in VB. Please help While loading it through recordset I get this '????' .
Actually wat u want
Regards; Sherin PM Quadra Software Solutions Pvt. Ltd. Email:Sherin_pm85@yahoo.com
-
Hello friends, I stored an image from my front end(VB) into SQL database on a datatype image. Then how can I show that image in VB. Please help While loading it through recordset I get this '????' .
This is the sample Code where 'FileContent' is the field name of Image and it will save the file in C:\ to open File, where document COde is the primary key in table.This Code opens all kind of File. Dim RstRpt As New ADODB.Recordset Set RstRpt = "Select FILECONTENT from tablename" _ & " Where DOCUMENTCODE ='" TXTBOX1.TEXT & "',CNN,ADOPENKEYSET) Set strStream = New ADODB.Stream strStream.Type = adTypeBinary strStream.Open strStream.Write RstRpt.Fields("FILECONTENT").Value DestinationFile = "C:\" & Trim(TXTBOX1.TEXT ) strStream.SaveToFile (DestinationFile), adSaveCreateOverWrite 'FileCopy SourceFile, DestinationFile SetAttr DestinationFile, vbNormal Call ShellExecute(hwnd, "Open", DestinationFile, "", "C:\", 1) Hopefully i will help u Ali
-
This is the sample Code where 'FileContent' is the field name of Image and it will save the file in C:\ to open File, where document COde is the primary key in table.This Code opens all kind of File. Dim RstRpt As New ADODB.Recordset Set RstRpt = "Select FILECONTENT from tablename" _ & " Where DOCUMENTCODE ='" TXTBOX1.TEXT & "',CNN,ADOPENKEYSET) Set strStream = New ADODB.Stream strStream.Type = adTypeBinary strStream.Open strStream.Write RstRpt.Fields("FILECONTENT").Value DestinationFile = "C:\" & Trim(TXTBOX1.TEXT ) strStream.SaveToFile (DestinationFile), adSaveCreateOverWrite 'FileCopy SourceFile, DestinationFile SetAttr DestinationFile, vbNormal Call ShellExecute(hwnd, "Open", DestinationFile, "", "C:\", 1) Hopefully i will help u Ali
Hi friend, I was not at site for these days. That's why i cant reply you. So what is this 'ShellExecute' i can't made it. Is there any references to add? by Dileeeeeeeeeeep.
-
This is the sample Code where 'FileContent' is the field name of Image and it will save the file in C:\ to open File, where document COde is the primary key in table.This Code opens all kind of File. Dim RstRpt As New ADODB.Recordset Set RstRpt = "Select FILECONTENT from tablename" _ & " Where DOCUMENTCODE ='" TXTBOX1.TEXT & "',CNN,ADOPENKEYSET) Set strStream = New ADODB.Stream strStream.Type = adTypeBinary strStream.Open strStream.Write RstRpt.Fields("FILECONTENT").Value DestinationFile = "C:\" & Trim(TXTBOX1.TEXT ) strStream.SaveToFile (DestinationFile), adSaveCreateOverWrite 'FileCopy SourceFile, DestinationFile SetAttr DestinationFile, vbNormal Call ShellExecute(hwnd, "Open", DestinationFile, "", "C:\", 1) Hopefully i will help u Ali
Hi' a file is created but it is not a picture format.
-
Hello friends, I stored an image from my front end(VB) into SQL database on a datatype image. Then how can I show that image in VB. Please help While loading it through recordset I get this '????' .
So, Let's start from Scratch U have to set the datatype of this fiel is null because there is no way to insert an image with other data. First u insert the other info in table and leave it null then update this row by sending the image.Remember 'FileContent' is the field name of Image. Data will be store in Binary Form and when u will retrieve it it will need space to store itself to be opened. Here is the Code to Insert first. AdoConne.Execute "Insert into DMSDOCCONTENTTRN (DOCUMENTCODE) values ('" _ & Trim(lbl_DocumentCode.Caption) & "')" 'Now send the Image or Any file in Binary Form.It will take some time depends upon the size of file so have patience. Dim mFIlePath As String Dim RstRecordset As New ADODB.Recordset If RstRecordset.state = 1 Then RstRecordset.Close RstRecordset.CursorLocation = adUseClient RstRecordset.Open "Select * from DMSDOCCONTENTTRN Where DOCUMENTCODE = '" & (lbl_DocumentCode.Caption) & "'", AdoConne, adOpenDynamic, adLockOptimistic Dim b b = RstRecordset.RecordCount Set strStream = New ADODB.Stream strStream.Type = adTypeBinary strStream.Open strStream.LoadFromFile Trim(lvw_LoadFile.ListItems(Lint_LoopFile).Text) RstRecordset.Fields("FILECONTENT").Value = strStream.Read RstRecordset.Update Now File has been store in Database Completely and First Phase is Completed. Now u need to download it. So Wait I simplify the Code for U... Wait
-
So, Let's start from Scratch U have to set the datatype of this fiel is null because there is no way to insert an image with other data. First u insert the other info in table and leave it null then update this row by sending the image.Remember 'FileContent' is the field name of Image. Data will be store in Binary Form and when u will retrieve it it will need space to store itself to be opened. Here is the Code to Insert first. AdoConne.Execute "Insert into DMSDOCCONTENTTRN (DOCUMENTCODE) values ('" _ & Trim(lbl_DocumentCode.Caption) & "')" 'Now send the Image or Any file in Binary Form.It will take some time depends upon the size of file so have patience. Dim mFIlePath As String Dim RstRecordset As New ADODB.Recordset If RstRecordset.state = 1 Then RstRecordset.Close RstRecordset.CursorLocation = adUseClient RstRecordset.Open "Select * from DMSDOCCONTENTTRN Where DOCUMENTCODE = '" & (lbl_DocumentCode.Caption) & "'", AdoConne, adOpenDynamic, adLockOptimistic Dim b b = RstRecordset.RecordCount Set strStream = New ADODB.Stream strStream.Type = adTypeBinary strStream.Open strStream.LoadFromFile Trim(lvw_LoadFile.ListItems(Lint_LoopFile).Text) RstRecordset.Fields("FILECONTENT").Value = strStream.Read RstRecordset.Update Now File has been store in Database Completely and First Phase is Completed. Now u need to download it. So Wait I simplify the Code for U... Wait
For Downloding... 'Declare on Gen.DECLARATION Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long 'This line is also declared on Declaration with both,uploading and downloading Dim strStream As ADODB.Stream Dim RstRpt As New ADODB.Recordset Set RstRpt = ModFncRecordSetReturnRst("Select FILECONTENT from DMSDOCCONTENTTRN" _ & " Where DOCUMENTCODE ='" & txtcode.text & "'") If RstRpt.RecordCount > 0 Then Set strStream = New ADODB.Stream strStream.Type = adTypeBinary strStream.Open strStream.Write RstRpt.Fields("FILECONTENT").Value DestinationFile = "C:\" & txtcode.text strStream.SaveToFile (DestinationFile), adSaveCreateOverWrite 'FileCopy SourceFile, DestinationFile SetAttr DestinationFile, vbNormal Call ShellExecute(hwnd, "Open", DestinationFile, "", "C:\", 1) 'it will save it in C:\ and Open it from the C:\ Path 'In case of Any Trouble Ask me. Take Care. Bye. Regards; Ali