Click here to Skip to main content
15,741,688 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to export my excel sheet data to table..
In my excel sheet[$Marks] I have two fields StuNo,Marks. I want to these fields values into mytable which one is already existed...
[no name] 24-Apr-12 7:57am    
What have you tried? What errors are you getting? Where is the relevant section of code? Even bother searching?

Try this (change excel path in connectionstring

 OleDbConnection con = null;
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\testExcel.xls;Extended Properties='Excel 8.0;HDR=YES;'";

con = new OleDbConnection(connectionString);

            if (con.State == ConnectionState.Open)
                OleDbCommand cmd = con.CreateCommand();
                cmd.CommandText = "Select * from [Sheet1$]";
                cmd.CommandType = CommandType.Text;
                OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                DataTable table = new DataTable();


Once this is done you can use this datatable object to put the data anywhere be it UI or any DB table.
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