0

I have a table called Messages which has a field called Attachment. The Attachment field uses a data type of "image" and binary data is inserted into that field whenever a file is uploaded from my website.

This is the code to insert the attachment into the database:

string cmdAnnouncement = "INSERT INTO Messages([AnnouncementCategoryId], [Subject], [Body], [CreateDate], [CreateMemberId], [MemberOnly], [Attachment]) VALUES ('" + selCategory.SelectedItem.Value + "', '" + txtSubject.Text + "', '" + txtBody.Text + "', '" + DateTime.Now + "', '" + readID.GetInt32(0) + "', '" + true + "', '" + fileUpload.FileBytes + "')";

SqlCommand cmd = db.executeSQL(cmdAnnouncement);

YES I know I should use parameters but leave me alone about that for now. So, as it seems, the attachment goes into the database fine. But I run into a problem when trying to allow users to download the attachment from the database.

I basically don't know what to do to allow the users to download the attachment. I want a hyperlink to be inserted onto my websites page and when the users click a specific hyperlink, they are directed to a specific attachment and are allowed to download it. Please explain how I can make this.

Edited by shaqtus: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by __avd
0

Firstly you can't insert array of bytes (fileUpload.FileBytes) into a table via sql string. Use @Parameterized query. (See MSDN pages - Parameterized query).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.