C# Reading Excel File

I have the following Data in Excel file
StudentID  Name   place        State    Phone
   1             John    Edision       NJ        ---

and lot more records in the same format. Now I want to Read the Excel file using C# .NET 1.1 Framework WebForm and dump into SQL Server 2000 Table with the same number of fields. Can a Live example be shown
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can do this is by using OleDb,

Solution found here:
This approach is extremely useful when you need to read the 
data from an Excel file fast and store the data in a DataTable
for further usage.
using System.Data;
using System.Data.OleDb;
String sConnectionString = 
"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + [Your Excel File Name Here] + ";" +
"Extended Properties=Excel 8.0;";
OleDbConnection objConn = new OleDbConnection(sConnectionString);
OleDbCommand objCmdSelect =new OleDbCommand("SELECT * FROM [Sheet1$]", objConn);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = objCmdSelect;
DataSet objDataset1 = new DataSet();

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Shanmuga SundaramDirector of Software EngineeringCommented:

protected void loadexcel()
       string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
               "Data Source=" + path + " ;" +
                        "Extended Properties=Excel 8.0;";
       FileUpload1.SaveAs(@"C:\\" + FileUpload1.FileName);
       string path = "C:\\" + FileUpload1.FileName;
       string str_name = "["+txtname.Text + "$" + "]";
       string str_con= "SELECT * FROM " + str_name + "  " ;
       OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM " + str_name + " ", strConn);
       DataSet myDataSet = new DataSet();
       DataGrid2.DataSource = myDataSet.Tables[0].DefaultView;

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.