how to insert a file into a varbinary(MAX) field in SQL Server using .NET code

preferably using VB .Net, i'd like to insert a file (Word document, Excel, PDF, text) into a SQL database varbinary column, and also extract and save the file from the database.

there are other fields that get inserted, and that happens with this code:

          Dim TheSQLConnection As New System.Data.SqlClient.SqlConnection
          Dim TheSQLCommand As New System.Data.SqlClient.SqlCommand
          Dim TheInsertString as string

... open the connection using a connection string
... set the value of TheInsertString to an insert query

          TheSQLCommand.Connection = TheSQLConnection
          TheSQLCommand.CommandText = TheInsertString

i'm not sure how to add the file to the insert command, or if there is another way to get this done.

this is quite easy to do in MS Access, using the Attachment field type but seems to be more difficult to do with SQL Server.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alpesh PatelAssistant ConsultantCommented:
No way is same as you depicted. Just do the thing first. Read file in binary mode and save it to database field as you mentioned.
Aaron ShiloChief Database ArchitectCommented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RBECKMNAuthor Commented:
i had this up and running in about 15 minutes.  the ASP suggestion would probably also work, but in this case, i'm not looking for a web-based application.  thanks for the help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.