Click here to Skip to main content
15,074,483 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
if (FileUpload1.HasFile)
{
    string path =  (FileUpload1.PostedFile.FileName);
    FileUpload1.SaveAs(Server.MapPath(path));
    
   // string path1 = FileUpload1.PostedFile.FileName;
    string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;Persist Security Info=False";
    OleDbConnection excelconnection = new OleDbConnection(excelConnectionString);
    OleDbCommand cmd=new OleDbCommand("select [Quastion],[OptionA],[OptionB],[OptionC],[OptionD],[OptionE],[AnswerKey],[Difficulty],[Level] from [Sheet1$]",excelconnection);
    con.Open();
    excelconnection.Open();
    OleDbDataReader dreader;
    dreader=cmd.ExecuteReader();
    SqlBulkCopy sqlbulk = new SqlBulkCopy(con);
    sqlbulk.DestinationTableName = "quastion";
    sqlbulk.WriteToServer(dreader);
    excelconnection.Close();
    con.Close();
}
Posted
Updated 26-Mar-14 1:51am
v2
Comments
bhagyadeep 26-Mar-14 7:50am
   
plz hlp me!!!!!!!!!!!!!!!!!!!!!
Richard MacCutchan 26-Mar-14 7:52am
   
With what? The message is quite clear, you are missing a filename. Use your debugger to find out why.
bhagyadeep 26-Mar-14 7:53am
   
i upload file in filecontroler
bhagyadeep 26-Mar-14 7:56am
   
i chacked using debudder point but get above error in "excelconnection.Open();"
Richard MacCutchan 26-Mar-14 7:59am
   
What is the value in path?
bhagyadeep 26-Mar-14 8:03am
   
its file name value

1 solution

   
Comments
bhagyadeep 26-Mar-14 8:15am
   
actly i used framwork 4.0........
Dixit Ashish 26-Mar-14 8:22am
   
plz check below two lines in your code..

con.Open();
excelconnection.Open();
bhagyadeep 26-Mar-14 8:33am
   
error generat in excelconnection.Open(); this line!!!
Dixit Ashish 26-Mar-14 8:35am
   
remove con.Open(); and debug the code..!!
bhagyadeep 26-Mar-14 9:15am
   
i also try but same error

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



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