copy file to SQL sever db HELP

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

how do you copy a file from a folder into a part of SQL server database
any sample code for VB .NE
ti
PT
 
PTH,

The method I used to insert a file into SQL Server was using an image
field and inserting the file like a normal parameter. The code I have is
in c# but a translation to VB.net should be trivial.

BinaryReader br = null;
byte [] buffer = null;

SqlCommand cmd = new SqlCommand("InsertFileStoredProc", myConn);
cmd.CommandType = CommandType.StoredProcedure;

//Create attachment parameter
cmd.Parameters.Add("@Attachment", SqlDbType.Image);

//Put attachment into byte array
br = new BinaryReader(file.FileStream);
buffer = br.ReadBytes((int)br.BaseStream.Length);

//Set parameter values
cmd.Parameters["@Attachment"].Value = buffer;

//Insert attachment file
cmd.ExecuteNonQuery();

InsertFileStoredProc would look something like this:
CREATE PROCEDURE dbo.InsertFileStoredProc
@AttachmentFile image
AS

INSERT INTO
AttachmentFiles ( AttachmentFile)
VALUES
(@Attachment)

RETURN

There is another method you can use that splits up the file into smaller
parts but I found that it was much slower and seeing as I cannot find the
links I'll let someone else (who know's it better) describe it.

Good luck.

Wes Brown
 
thanks we
i'll try to translate this noto vb.net code
....another task is to have the loops for stroring series of files as part of record
 
Back
Top