Binary read jpeg and store it in SQL Server db
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
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
精彩评论