View Full Version : fileupload to SQL database

07-20-2011, 11:29 PM
Hey all.
I have a fileupload control and I have been searching for hours on how to pass the file to a string so i can pass it to my database. All I can find is information about how to use SaveAs() method to save to a physical path... I do not want to do it this way, I want to pass it to my database.

snippets of my code

/* Between these lines of comments is the area I am stuck on !!!!! **** */
// extract the file to upload as text and the name as well

/* Between these lines of comments is the area I am stuck on !!!!! **** */

name = this.txt_fileName.Text;

// set up the string accessing config file and then set up connection "conn"
string connstring = WebConfigurationManager.ConnectionStrings["DanaConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(connstring);

// set up sql command for stroed proc
SqlCommand loadFile = new SqlCommand("usp_insert_tbl_documnets", conn);
loadFile.CommandType = CommandType.StoredProcedure;
// set up the parameters to pass to the stored proc
loadFile.Parameters.Add(new SqlParameter("@name", name));
loadFile.Parameters.Add(new SqlParameter("@extension", extension));
loadFile.Parameters.Add(new SqlParameter("@dateset", dateset));
loadFile.Parameters.Add(new SqlParameter("@documents", documents));
// end of setting up parameters to pass to stored proc
conn.Open(); //open connection
loadFile.Connection = conn; // set connection for command
loadFile.ExecuteNonQuery(); //execute the command
conn.Close(); // close connection

and my database variables

TAB_ID type int
document type text
name type varchar(50)
extension type char(4)
dateset type varchar(50)

I provided DB stuff bc I assume there is no issue with passing a document to type text... the files being uploaded will be of type .html/.htm