0

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 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks sLaks. One question. the image is not in my C drive it is in a location on the server how can I read it like My.Computer.FileSystem.ReadAllBytes _ ("C:/Documents and Settings/selfportrait.jpg") This is the location of the files Server.MapPath("images\Signatures\") & Session("NetworkID").ToString() & ".jpeg")
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.