rss feed Rss FeedAsp.net Coder
learn asp.net & visual studio 2008,this blog share our study record.there are a lot of solution and source code of building web application using asp.net

how to save image in oracle blob field?

Author:powerZ  PostAt:Wed, 26 Nov 2008 11:37:04 GMT Posted In:Ado.net
Q:

Hello All,

I m using vb.net2002-03. 

Can you tell me the code how to store the image in the oracle blob field?i tried but not succeed..so storing path temporarily..i want to store image it self in to database and also want to reirieve from the blob field...

I think i've to read that image in to byte array by giving path and then store the image...

and i am using oledb for that and not oracle client and i think to store this i've to add system.oracle client.dll from the add reference of  project menu.

so if possible please privide me code snippet in vb.net or provide me any link that contains the similar article.....i'll be thankful to you...

Thanks & Regards,

Nil

"Problem is just the distance between the expectation and the reality" 

A:

here

http://www.codeproject.com/useritems/Blobfield.asp

 

A:Thanks a lot for reply....i'll try this out...
A:

create table image_blob_table (id                number primary key,

                               width             integer,

                               height            integer,

                               contentLength     integer,

                               mimeType          varchar2(20),

                               image_blob        BLOB);

 

or

 

 

 

create table graphics_table (

  bfile_id number,

  bfile_desc varchar2(30),

  bfile_loc bfile,

  bfile_type varchar2(4))

  TABLESPACE appl_data

  storage (initial 1m next 1m pctincrease 0)

 /

 

 

 

 

SQL> INSERT INTO graphics_table

  2  VALUES(4,'April Book of Days Woodcut',bfilename('GIF_FILES','APRIL.JPG'),'JPEG');

1 row created.

SQL> INSERT INTO graphics_table

  2  VALUES(8,'August Book of Days Woodcut',bfilename('GIF_FILES','AUGUST.JPG'),'JPEG');

1 row created.

SQL> INSERT INTO graphics_table

  2  VALUES(13,'Benzene Molecule',bfilename('GIF_FILES','BENZNE.GIF'),'GIF');

1 row created.

.

.

.

SQL> INSERT INTO graphics_table

  2  VALUES(30,'',bfilename('GIF_FILES','SHAPIROS.GIF'),'GIF');

1 row created.

SQL> INSERT INTO graphics_table

  2  VALUES(31,'',bfilename('GIF_FILES','SODF5.GIF'),'GIF');

1 row created.

SQL> INSERT INTO graphics_table

  2  VALUES(32,'',bfilename('GIF_FILES','WAVRA-CL.GIF'),'GIF');

1 row created.

SQL> commit;

Commit complete.

 

 

 

CREATE  OR REPLACE PROCEDURE get_bfiles(

                                        bfile_dir in  VARCHAR2,

                                        bfile_lis in  VARCHAR2,

                                        bfile_int_dir VARCHAR2)

AS

 cur           INTEGER;

 bfile_int    VARCHAR2(100);

 sql_com   VARCHAR2(2000);

 file_proc   INTEGER;

 file_hand  utl_file.file_type;

 file_buff    VARCHAR2(1022);

 file_type   VARCHAR2(4);

BEGIN

 bfile_int:=UPPER(bfile_int_dir);

 file_hand:=utl_file.fopen(bfile_dir,bfile_lis,'R');

 LOOP

   BEGIN

   utl_file.get_line(file_hand,file_buff);

   cur:=dbms_sql.open_cursor;

   file_type:=SUBSTR(file_buff,INSTR(file_buff,'.')+1,3);

   file_type:=UPPER(file_type);

   IF file_type='GIF'

    THEN

        file_type:='GIF';

    ELSIF file_type='JPG'

    THEN file_type:='JPEG';

   END IF; 

   sql_com:= 'INSERT INTO graphics_table '||CHR(10)||

             'VALUES (graphics_table_seq.NEXTVAL,'||CHR(39)||CHR(39)||

             ', bfilename('||

             CHR(39)||bfile_int||CHR(39)||','

             ||CHR(39)||file_buff||CHR(39)||

             ') ,'||CHR(39)||file_type||CHR(39)||')';

   dbms_output.put_line(sql_com);

   dbms_sql.parse(cur,sql_com,dbms_sql.v7);

   file_proc:=dbms_sql.execute(cur);

   dbms_sql.close_cursor(cur);

   EXCEPTION

    WHEN no_data_found THEN

   EXIT;

   END;

 END LOOP;

 utl_file.fclose(file_hand);

END;

/

 

 

 

CREATE OR REPLACE PROCEDURE load_lob AS

  id         NUMBER;

  image1     BLOB;

  locator    BFILE;

  bfile_len  NUMBER;

  bf_desc    VARCHAR2(30);

  bf_name    VARCHAR2(30);

  bf_dir     VARCHAR2(30);

  bf_typ     VARCHAR2(4);

  ctr integer;

  CURSOR get_id IS

    SELECT bfile_id,bfile_desc,bfile_type FROM graphics_table;

BEGIN

  OPEN get_id;

LOOP

  FETCH get_id INTO id, bf_desc, bf_typ;

  EXIT WHEN get_id%notfound;

  dbms_output.put_line('ID: '||to_char(id));

  SELECT bfile_loc INTO locator FROM graphics_table WHERE bfile_id=id;

  dbms_lob.filegetname(

locator,bf_dir,bf_name);

  dbms_output.put_line('Dir: '||bf_dir);

  dbms_lob.fileopen(locator,dbms_lob.file_readonly);

  bfile_len:=dbms_lob.getlength(locator);

  dbms_output.put_line('ID: '||to_char(id)||' length: '||to_char(bfile_len));

  SELECT temp_blob INTO image1 FROM temp_blob;

  bfile_len:=dbms_lob.getlength(locator);

  dbms_lob.loadfromfile(image1,locator,bfile_len,1,1);

  INSERT INTO internal_graphics VALUES (id,bf_desc,image1,bf_typ);

  dbms_output.put_line(bf_desc||' Length: '||TO_CHAR(bfile_len)||

  ' Name: '||bf_name||' Dir: '||bf_dir||' '||bf_typ);

  dbms_lob.fileclose(locator);

END LOOP;

END;

/

 

 

 

A:

Give this a read, http://aspalliance.com/570_Read_and_Write_BLOB_Data_to_a_Database_Table_with_ODPNET. The code sample is available for download as well.

A:

I currently use Enterprise Library 2.0 to access the Oracle 9i. Everything works fine except when I need to insert Blob data. I noticed that OLE DB is used instead ODP.NET. I use binary to raw type conversion for the image date but it never worked. I don't have any problem to do so with ODP.NET. My question is, can I still able to do the same thing WITHOUT ODP.NET?

Can anyone advise me on this?

Previous: Import .sql file content into oracle database using C#.NET
I have a .sql file that has insert statements in it. It can be imported into DB using sqlplus editor.The syntax is SQL> @sql file path.I want to import it through C#.NET into DB. Can anyone suggest some way? ... more
Next: None