Hi,
I do it like this:
Import System.Data.SqlClient
Import System.IO
....
.....
.....
dim strFileName = ....
dim myFile as System.IO.FileInfo
dim bw as BinaryWriter
dim br as BinaryReader
dim lngFileSize as long
dim arybyteFileData() as Byte
dim strFileName as string
dim mda as new SQLClient.SqlDataAdapter
dim cmdInsert as new SqlClient.SqlCommand
dim strReadFromFile as string = txtFileName.Text // file name entered
in text box
If File.Exists(strFileName) Then
Dim anImage() as Byte = GetImage(strFileName) // se below
myFile = new System.IO.FileInfo(fileName:=strReadFromFile)
lngFileSize = myFile.Length
strFileName = myFile.Name
Redim arybyteFileData(lngFileSize)
strSQL = "INSERT INTO myTable ( .... ) VALUES( @parID,
@parDateAdded, @parImage, @parFileName)
cmdInsert.CommandText = strSQL
cmdInsert.Parameters.Add("@parID", SQLDbTyhpe.BigInt, 8).Value =
lngDocID // if you add image data to another table and actual bytes
in this table (myTable), then you have the id of that image already
cmdInsert.Parameters.Add("@parDateAdded", SQlDbType.DateTime).value
= ...
cmdInsert.Parametes.Add("@parImage", SqlDbType.Image,
anImage.Length).Value = anImage
mda.InsertCommand = cmdInsert
mda.InsertCommand.ExecuteNonQuery()
end if
public Function GetImage(ByVal strFilePath as string) as Byte()
Dim fs as FileStream = new FileStream(strFilePath, FileMode.Open,
FileAccess.Read)
dim br as BinaryWriter = new BinaryWriter(fs.Length)
dim theImage() as Byte = br.ReadBytes(fs.Length)
br.close()
fs.Close()
retrun theImage
end function
HTH
Dino