Image Data  
Author Message
Tibery-OS





PostPosted: Tue Mar 01 08:02:08 CST 2005 Top

SQL Server Developer >> Image Data

What is the correct (or best way) to
Insert Into an Image data field.

I have an app that displays records containing Equipment Pictures.
I am able to display the record and display the picture.

I want to allow the user to add an new record and also insert a
new picture associated with the record.

The table was imported so the existing pictures came in fine
but I now need to build the app to facilitate this needed
functionality.

any help is much appreciated.
thanks in advance,
bob mcclellan

SQL Server70  
 
 
Madhivanan





PostPosted: Tue Mar 01 08:02:08 CST 2005 Top

SQL Server Developer >> Image Data
You can store the physical path of the pictures in one column and it is
better to hide that file

Madhivanan

 
 
Uri





PostPosted: Tue Mar 01 08:00:09 CST 2005 Top

SQL Server Developer >> Image Data One of the option is this script wriiten by (If I remember well) Dan Guzman
Dim ADOCmd As New ADODB.Command
Dim ADOprm As New ADODB.Parameter
Dim ADOcon As ADODB.Connection
Dim intFile As Integer
Dim ImgBuff() As Byte
Dim ImgLen As Long

Set ADOcon = New ADODB.Connection
With ADOcon
.Provider = "MSDASQL"
.CursorLocation = adUseClient
.ConnectionString = "driver=
{SQL Server};server=(local);uid=<username>;pwd=<strong
password>;database=pubs"
.Open
End With

'Change this to the path of a GIF file you want to use for testing.
IMG_FILE_GIF = "E:\Graphics\GIF\Image.gif"

'Read/Store GIF file in ByteArray
intFile = FreeFile
Open IMG_FILE_GIF For Binary As #intFile
ImgLen = LOF(intFile)
ReDim ImgBuff(ImgLen) As Byte
Get #intFile, , ImgBuff()
Close #intFile

Set ADOCmd.ActiveConnection = ADOcon
ADOCmd.CommandType = adCmdStoredProc
ADOCmd.CommandText = "uspInsertBLOB"

Set ADOprm = ADOCmd.CreateParameter(, adChar, adParamInput, 1, "1")
ADOCmd.Parameters.Append ADOprm

'The datatype must be specified as adLongVarBinary

'For the code to function correctly comment this line.

Set ADOprm = ADOCmd.CreateParameter(, adLongVarBinary, _
adParamInput, ImgLen)

'Uncomment this line.
'Set ADOprm = ADOCmd.CreateParameter(, adLongVarBinary, _
adParamInput, (ImgLen + 1))
ADOCmd.Parameters.Append ADOprm

'Set the Value of the parameter with the AppendChunk method.

ADOprm.AppendChunk ImgBuff()

'The preceding example assumes you are using a small image file.
'See the article reference in the REFERENCES section for handling a
'large image file.

ADOCmd.Execute

Set ADOCmd = Nothing
Set ADOprm = Nothing





> What is the correct (or best way) to
> Insert Into an Image data field.
>
> I have an app that displays records containing Equipment Pictures.
> I am able to display the record and display the picture.
>
> I want to allow the user to add an new record and also insert a
> new picture associated with the record.
>
> The table was imported so the existing pictures came in fine
> but I now need to build the app to facilitate this needed
> functionality.
>
> any help is much appreciated.
> thanks in advance,
> bob mcclellan
>
>


 
 
John316





PostPosted: Tue Mar 01 08:19:53 CST 2005 Top

SQL Server Developer >> Image Data Thanks Uri !
I will try this out.

thanks much for the reply.
It is much appreciated.

bob




> One of the option is this script wriiten by (If I remember well) Dan
> Guzman
> Dim ADOCmd As New ADODB.Command
> Dim ADOprm As New ADODB.Parameter
> Dim ADOcon As ADODB.Connection
> Dim intFile As Integer
> Dim ImgBuff() As Byte
> Dim ImgLen As Long
>
> Set ADOcon = New ADODB.Connection
> With ADOcon
> .Provider = "MSDASQL"
> .CursorLocation = adUseClient
> .ConnectionString = "driver=
> {SQL Server};server=(local);uid=<username>;pwd=<strong
> password>;database=pubs"
> .Open
> End With
>
> 'Change this to the path of a GIF file you want to use for testing.
> IMG_FILE_GIF = "E:\Graphics\GIF\Image.gif"
>
> 'Read/Store GIF file in ByteArray
> intFile = FreeFile
> Open IMG_FILE_GIF For Binary As #intFile
> ImgLen = LOF(intFile)
> ReDim ImgBuff(ImgLen) As Byte
> Get #intFile, , ImgBuff()
> Close #intFile
>
> Set ADOCmd.ActiveConnection = ADOcon
> ADOCmd.CommandType = adCmdStoredProc
> ADOCmd.CommandText = "uspInsertBLOB"
>
> Set ADOprm = ADOCmd.CreateParameter(, adChar, adParamInput, 1, "1")
> ADOCmd.Parameters.Append ADOprm
>
> 'The datatype must be specified as adLongVarBinary
>
> 'For the code to function correctly comment this line.
>
> Set ADOprm = ADOCmd.CreateParameter(, adLongVarBinary, _
> adParamInput, ImgLen)
>
> 'Uncomment this line.
> 'Set ADOprm = ADOCmd.CreateParameter(, adLongVarBinary, _
> adParamInput, (ImgLen + 1))
> ADOCmd.Parameters.Append ADOprm
>
> 'Set the Value of the parameter with the AppendChunk method.
>
> ADOprm.AppendChunk ImgBuff()
>
> 'The preceding example assumes you are using a small image file.
> 'See the article reference in the REFERENCES section for handling a
> 'large image file.
>
> ADOCmd.Execute
>
> Set ADOCmd = Nothing
> Set ADOprm = Nothing
>
>
>


>> What is the correct (or best way) to
>> Insert Into an Image data field.
>>
>> I have an app that displays records containing Equipment Pictures.
>> I am able to display the record and display the picture.
>>
>> I want to allow the user to add an new record and also insert a
>> new picture associated with the record.
>>
>> The table was imported so the existing pictures came in fine
>> but I now need to build the app to facilitate this needed
>> functionality.
>>
>> any help is much appreciated.
>> thanks in advance,
>> bob mcclellan
>>
>>
>
>