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?
tempstf1Connect With a Mentor Commented:
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

Shanmuga SundaramConnect With a Mentor Director 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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.