Click here to Skip to main content
15,747,637 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
protected void uploadFile_Click(object sender, EventArgs e)
    {
        OleDbConnection wpCon = new OleDbConnection(connection);
        wpCon.Open();
        

        if (FileUploadMulti.HasFile)
        {
            foreach (HttpPostedFile uploadedFile in FileUploadMulti.PostedFiles)
        {
                if(System.IO.Directory.Exists(Server.MapPath("~/img/")))
                {
                    System.IO.Directory.CreateDirectory(MapPath("~/img/whitepaper/"));
            uploadedFile.SaveAs(System.IO.Path.Combine(Server.MapPath("~/img/whitepaper/"), uploadedFile.FileName));

           // string uplodFileURL = uploadedFile.SaveAs(System.IO.Path.Combine(Server.MapPath("~/img/whitepaper/"), uploadedFile.FileName));
            string FileNm = uploadedFile.FileName;
            long FileSz =Convert.ToInt64(uploadedFile.ContentLength / 1024f);

            string wpInsertQuery = "Insert into WhitePaper_Table ([FileNm],[FileSz])" + " values(" + FileNm + "," + FileSz + ")";

            OleDbCommand cmdOldb = new OleDbCommand(wpInsertQuery, wpCon);
            OleDbDataAdapter adpOldb = new OleDbDataAdapter(cmdOldb);
            //OleDbDataReader redOldb = cmdOldb.ExecuteNonQuery();
            cmdOldb.ExecuteNonQuery(); 
                    //listofuploadedfiles.Text += String.Format("{0}<br />", uploadedFile.FileName);
               
                
                
                
                }
                
            
            }
        
        
        }
    }
Posted
Updated 25-Nov-14 21:57pm
v2

1 solution

You're missing apostrophes (single quotes) for string insert

Consider using String.Format for your query or better yet parametrized query or the best stored procedure.

C#
string wpInsertQuery = String.Format("Insert into WhitePaper_Table ([FileNm],[FileSz]) values('{0}','{1}')", FileNm, FileSz)
;

See how you can read it easier without all the plusses and closing and opening the quotes? And you see exactly how it looks before sending it to the database.

That said, if you absolutely have to have database code in your code instead of stored procedure, set a breakpoint right after the query string and copy its content into your database console and try to execute it. Correct whatever errors you have and then return it to the code.

If this helpls please take time to accept the solution. Thank you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900