Link to home
Start Free TrialLog in
Avatar of arichexe
arichexe

asked on

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);
ASKER CERTIFIED SOLUTION
Avatar of Joel Coehoorn
Joel Coehoorn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I missed a \ character on the second line- you don't need to escape them in VB.