tags:

views:

23

answers:

1

Hello, I have a jpeg file in my C drive from my vb.net application I want to binary read it and store it in SQL server. How can I do that? Thanks

+1  A: 

You can read a file into a byte array by calling File.ReadAllBytes.

You can then put the byte array into SQL Server using a SqlParameter.

For example:

Using command As New SqlCommand("INSERT INTO sometable VALUES(@image)", connection)
    command.Parameters.AddWithValue("image", File.ReadAllBytes(path))
    command.ExecuteNonQuery()
End Using
SLaks
acadia
As long as it's on a local disk, you can still read it. If it was uploaded by the user, you can also get a byte array by reading `Request.Files[0].InputStream` or the `FileBytes` property of the `FileUpload` control.
SLaks