C# Reading Excel File

Hi,
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
dotnet0824Asked:
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.

tempstf1Commented:
You can do this is by using OleDb,

Solution found here:
http://zamov.online.fr/EXHTML/CSharp/CSharp4.html
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);
 
objConn.Open();
 
OleDbCommand objCmdSelect =new OleDbCommand("SELECT * FROM [Sheet1$]", objConn);
 
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
 
objAdapter1.SelectCommand = objCmdSelect;
 
DataSet objDataset1 = new DataSet();
 
objAdapter1.Fill(objDataset1);
 
objConn.Close();
  

Open in new window

0

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:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=107963&SiteID=1


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();
       myCommand.Fill(myDataSet);
       DataGrid2.DataSource = myDataSet.Tables[0].DefaultView;
       DataGrid2.DataBind();
}

Open in new window

0
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.