Attaching a file in an ASP.Net website

tmitch68 used Ask the Experts™

I have an ASP.Net web site I would like to allow the user to attach and upload files to.  I would like to allow them to do this using the database.

I've figured most of this out.  What I can't quite get is how to actually insert the file into the database.

I try to insert it as a varbinary array like so, but I always get an error that it can't be converted.

Any suggestions?

private int WriteToDB(string strName, string strType, ref byte[] Buffer)
        SqlDataSource2.InsertCommand = "INSERT INTO [AttachmentTable] ([FileName], [FileSize], [ContentType], [FileData]) VALUES ('" + strName + "' ," + Buffer.Length + ", '" + strType + "', '" + Buffer + "')";
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial