Inserting file into blob

The below C# snippet loads a .doc into a SQL image.  How would I code such in VB.NET?

FileStream MyStream = new FileStream("C:\\My.doc",FileMode.Open);
int DocLen = (int)new FileInfo("C:\\My.doc").Length;
byte[] MyBlob = new byte[DocLen];
int n = MyStream.Read(MyBlob,0,DocLen);

string MySql = "INSERT INTO MyBlobTable (MyId,MyBlob) VALUES (1,@MyBlob)";
SqlCommand sql = new SqlCommand(MySql,MyConn);
SqlParameter sqlp = new SqlParameter("@MyBlob",SqlDbType.Image);
sqlp.Value = MyBlob;
sql.Parameters.Add(sqlp);
arichexeAsked:
Who is Participating?
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.

Joel CoehoornDirector of Information TechnologyCommented:
This is just a direct translation of the code your provided.  It depends on the same Imports (like System.IO) and supporting objects (there a MyConn variable in the original who's source is not explained):
Dim MyStream As New FileStream("C:\My.doc",FileMode.Open)
Dim DocLen As Integer = New FileInfo("C:\\My.doc").Length
Dim MyBlob(DocLen) As Byte
Dim n As Integer = MyStream.Read(MyBlob,0,DocLen)
 
Dim MySql As Sting = "INSERT INTO MyBlobTable (MyId,MyBlob) VALUES (1,@MyBlob)"
Dim sql As New SqlCommand(MySql,MyConn)
Dim sqlp As New SqlParameter("@MyBlob",SqlDbType.Image)
sqlp.Value = MyBlob
sql.Parameters.Add(sqlp)

Open in new window

0

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
Joel CoehoornDirector of Information TechnologyCommented:
I missed a \ character on the second line- you don't need to escape them in VB.
0
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
Visual Basic.NET

From novice to tech pro — start learning today.