Save and load picture files in database by using ADO !(SRC) 
Author Message
 Save and load picture files in database by using ADO !(SRC)

ActiveX Data Objects (ADO) 2.5

 table structure
*************************************************
if exists (select * from sysobjects where id = object_id(N'[dbo].[TEST]')
and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[TEST]
GO

CREATE TABLE [dbo].[TEST] (
 [Picture] [image] NULL ,
 [ID] [int] NULL ,
 [FieldName] [varchar] (100) NOT NULL ,
 [Remark] [varchar] (200) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
**************************************************

 image class
**************************************************
Option Explicit

Public Function SavePicture(UserAdocon As ADODB.Connection, TableName As
String, FileName As String, Optional Remark As String = "")

  Dim rs As New ADODB.Recordset
  Dim mStream As New ADODB.Stream
  Dim SQL As String
  Dim ID As Integer

    UserAdocon.CursorLocation = adUseClient
    SQL = "select * from " & TableName
    rs.Open SQL, UserAdocon, adOpenKeyset, adLockOptimistic

    mStream.Type = adTypeBinary
    mStream.Open
    mStream.LoadFromFile FileName

    ID = rs.RecordCount + 1
    rs.AddNew
    rs.Fields("ID").Value = ID
    rs.Fields("FileName").Value = FileName
    rs.Fields("Image").Value = mStream.Read
    rs.Fields("Remark").Value = Remark
    rs.Update
End Function

Public Function LoadPicture(UserAdocon As ADODB.Connection, TableName As
String, OutFileName As String, Optional FileName As String = "", Optional
Remark As String = "")
  Dim rs As New ADODB.Recordset
  Dim mStream As New ADODB.Stream
  Dim SQL As String
  UserAdocon.CursorLocation = adUseClient

  SQL = "select * from " & TableName
  If Len(Trim(FileName)) > 0 Then
     SQL = SQL & " where FileName='" & FileName & "'"
  Else

  End If

    rs.Open SQL, UserAdocon, adOpenKeyset, adLockOptimistic

    mStream.Type = adTypeBinary
    mStream.Open
    mStream.Write rs.Fields("Image").Value
    mStream.SaveToFile OutFileName, adSaveCreateOverWrite

End Function

Public Function DeletePicture()
'develop by yourself
End Function



Fri, 06 May 2005 15:04:53 GMT  
 Save and load picture files in database by using ADO !(SRC)
I'm wondering why programmers write functions that don't return a value.
D.
Quote:

> ActiveX Data Objects (ADO) 2.5

>  table structure
> *************************************************
> if exists (select * from sysobjects where id = object_id(N'[dbo].[TEST]')
> and OBJECTPROPERTY(id, N'IsUserTable') = 1)
> drop table [dbo].[TEST]
> GO

> CREATE TABLE [dbo].[TEST] (
>  [Picture] [image] NULL ,
>  [ID] [int] NULL ,
>  [FieldName] [varchar] (100) NOT NULL ,
>  [Remark] [varchar] (200) NULL
> ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
> GO
> **************************************************

>  image class
> **************************************************
> Option Explicit

> Public Function SavePicture(UserAdocon As ADODB.Connection, TableName As
> String, FileName As String, Optional Remark As String = "")

>   Dim rs As New ADODB.Recordset
>   Dim mStream As New ADODB.Stream
>   Dim SQL As String
>   Dim ID As Integer

>     UserAdocon.CursorLocation = adUseClient
>     SQL = "select * from " & TableName
>     rs.Open SQL, UserAdocon, adOpenKeyset, adLockOptimistic

>     mStream.Type = adTypeBinary
>     mStream.Open
>     mStream.LoadFromFile FileName

>     ID = rs.RecordCount + 1
>     rs.AddNew
>     rs.Fields("ID").Value = ID
>     rs.Fields("FileName").Value = FileName
>     rs.Fields("Image").Value = mStream.Read
>     rs.Fields("Remark").Value = Remark
>     rs.Update
> End Function

> Public Function LoadPicture(UserAdocon As ADODB.Connection, TableName As
> String, OutFileName As String, Optional FileName As String = "", Optional
> Remark As String = "")
>   Dim rs As New ADODB.Recordset
>   Dim mStream As New ADODB.Stream
>   Dim SQL As String
>   UserAdocon.CursorLocation = adUseClient

>   SQL = "select * from " & TableName
>   If Len(Trim(FileName)) > 0 Then
>      SQL = SQL & " where FileName='" & FileName & "'"
>   Else

>   End If

>     rs.Open SQL, UserAdocon, adOpenKeyset, adLockOptimistic

>     mStream.Type = adTypeBinary
>     mStream.Open
>     mStream.Write rs.Fields("Image").Value
>     mStream.SaveToFile OutFileName, adSaveCreateOverWrite

> End Function

> Public Function DeletePicture()
> 'develop by yourself
> End Function



Fri, 06 May 2005 16:05:38 GMT  
 Save and load picture files in database by using ADO !(SRC)

define by user


Quote:
> I'm wondering why programmers write functions that don't return a value.
> D.


> > ActiveX Data Objects (ADO) 2.5

> >  table structure
> > *************************************************
> > if exists (select * from sysobjects where id =

object_id(N'[dbo].[TEST]')
Quote:
> > and OBJECTPROPERTY(id, N'IsUserTable') = 1)
> > drop table [dbo].[TEST]
> > GO

> > CREATE TABLE [dbo].[TEST] (
> >  [Picture] [image] NULL ,
> >  [ID] [int] NULL ,
> >  [FieldName] [varchar] (100) NOT NULL ,
> >  [Remark] [varchar] (200) NULL
> > ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
> > GO
> > **************************************************

> >  image class
> > **************************************************
> > Option Explicit

> > Public Function SavePicture(UserAdocon As ADODB.Connection, TableName As
> > String, FileName As String, Optional Remark As String = "")

> >   Dim rs As New ADODB.Recordset
> >   Dim mStream As New ADODB.Stream
> >   Dim SQL As String
> >   Dim ID As Integer

> >     UserAdocon.CursorLocation = adUseClient
> >     SQL = "select * from " & TableName
> >     rs.Open SQL, UserAdocon, adOpenKeyset, adLockOptimistic

> >     mStream.Type = adTypeBinary
> >     mStream.Open
> >     mStream.LoadFromFile FileName

> >     ID = rs.RecordCount + 1
> >     rs.AddNew
> >     rs.Fields("ID").Value = ID
> >     rs.Fields("FileName").Value = FileName
> >     rs.Fields("Image").Value = mStream.Read
> >     rs.Fields("Remark").Value = Remark
> >     rs.Update
> > End Function

> > Public Function LoadPicture(UserAdocon As ADODB.Connection, TableName As
> > String, OutFileName As String, Optional FileName As String = "",
Optional
> > Remark As String = "")
> >   Dim rs As New ADODB.Recordset
> >   Dim mStream As New ADODB.Stream
> >   Dim SQL As String
> >   UserAdocon.CursorLocation = adUseClient

> >   SQL = "select * from " & TableName
> >   If Len(Trim(FileName)) > 0 Then
> >      SQL = SQL & " where FileName='" & FileName & "'"
> >   Else

> >   End If

> >     rs.Open SQL, UserAdocon, adOpenKeyset, adLockOptimistic

> >     mStream.Type = adTypeBinary
> >     mStream.Open
> >     mStream.Write rs.Fields("Image").Value
> >     mStream.SaveToFile OutFileName, adSaveCreateOverWrite

> > End Function

> > Public Function DeletePicture()
> > 'develop by yourself
> > End Function



Fri, 06 May 2005 17:44:33 GMT  
 Save and load picture files in database by using ADO !(SRC)
This works for SQL Server - but I am having problems with it and an Access
table. I can read and save BMP file well enough - but JPG and GIF just come
out unreadable.


Quote:

> ActiveX Data Objects (ADO) 2.5

>  table structure
> *************************************************
> if exists (select * from sysobjects where id = object_id(N'[dbo].[TEST]')
> and OBJECTPROPERTY(id, N'IsUserTable') = 1)
> drop table [dbo].[TEST]
> GO

> CREATE TABLE [dbo].[TEST] (
>  [Picture] [image] NULL ,
>  [ID] [int] NULL ,
>  [FieldName] [varchar] (100) NOT NULL ,
>  [Remark] [varchar] (200) NULL
> ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
> GO
> **************************************************

>  image class
> **************************************************
> Option Explicit

> Public Function SavePicture(UserAdocon As ADODB.Connection, TableName As
> String, FileName As String, Optional Remark As String = "")

>   Dim rs As New ADODB.Recordset
>   Dim mStream As New ADODB.Stream
>   Dim SQL As String
>   Dim ID As Integer

>     UserAdocon.CursorLocation = adUseClient
>     SQL = "select * from " & TableName
>     rs.Open SQL, UserAdocon, adOpenKeyset, adLockOptimistic

>     mStream.Type = adTypeBinary
>     mStream.Open
>     mStream.LoadFromFile FileName

>     ID = rs.RecordCount + 1
>     rs.AddNew
>     rs.Fields("ID").Value = ID
>     rs.Fields("FileName").Value = FileName
>     rs.Fields("Image").Value = mStream.Read
>     rs.Fields("Remark").Value = Remark
>     rs.Update
> End Function

> Public Function LoadPicture(UserAdocon As ADODB.Connection, TableName As
> String, OutFileName As String, Optional FileName As String = "", Optional
> Remark As String = "")
>   Dim rs As New ADODB.Recordset
>   Dim mStream As New ADODB.Stream
>   Dim SQL As String
>   UserAdocon.CursorLocation = adUseClient

>   SQL = "select * from " & TableName
>   If Len(Trim(FileName)) > 0 Then
>      SQL = SQL & " where FileName='" & FileName & "'"
>   Else

>   End If

>     rs.Open SQL, UserAdocon, adOpenKeyset, adLockOptimistic

>     mStream.Type = adTypeBinary
>     mStream.Open
>     mStream.Write rs.Fields("Image").Value
>     mStream.SaveToFile OutFileName, adSaveCreateOverWrite

> End Function

> Public Function DeletePicture()
> 'develop by yourself
> End Function

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.391 / Virus Database: 222 - Release Date: 09/19/2002


Wed, 01 Jun 2005 04:33:23 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. How to store a picture from file in an access2000 database using ADO

2. Load XML file to a RecordSet then Update Database using ADO

3. Loading .wmf file into .res file and using in picture control

4. How to save an VB PaintBrush Picture in SQL 6.5 using ADO

5. Saving VB pictures in SQL using ADO

6. loading a picture from database using DAO-code

7. Saving pictures in database using dynaset

8. Saving pictures in database using dynaset

9. HOW TO SAVE AND RETRIVE PICTURES USING ORACLE DATABASE

10. Utility to pick pictures into Access database and save its as file

11. Save picture file from WWW directly to database

12. Save picture file from WWW directly to database

 

 
Powered by phpBB® Forum Software