473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Read one Excel File and write to database using c# .net 1.1

390 Expert 256MB
Hi,

Can anybody send me the code sample to read one excel file and write the content of the excel file to database.It is very urgent .
Please help me on the same.
Sep 11 '07 #1
1 7588
Hi mzmishra]Hi

private void Button1_Click(object sender, System.EventArgs e)
{
//this function will open an existing excel file and put the info into the dataset.
//from dataset you can now easily create a connection and another function that will append these records
//into your database...

//drag and drop the following object contron in your webform:
//1. Datagrid
//2. HTML File Field object control

//first specify the path and filename of your excel

string PathFilename = this.File1.PostedFile.FileName.ToString() ;
//second is specify the sheet name you want to read
string strSheetName = "Sheet1";
System.Data.OleDb.OleDbConnection MyConnection;
System.Data.DataSet DS;
System.Data.OleDb.OleDbDataAdapter MyCommand;
MyConnection = new System.Data.OleDb.OleDbConnection("provider=Micros oft.Jet.OLEDB.4.0;data source='" + PathFilename + "'; Extended Properties=Excel 8.0;");
//Select the data from Sheet1 of the workbook.
MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [" + strSheetName + "$]", MyConnection);
DS = new System.Data.DataSet();
MyCommand.Fill(DS);
MyConnection.Close();
MyConnection.Dispose();


this.DataGrid1.DataSource=DS;
this.DataGrid1.DataBind();

}

Best Regards,
Ruel


Hi,

Can anybody send me the code sample to read one excel file and write the content of the excel file to database.It is very urgent .
Please help me on the same.
Sep 11 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: see_mun_lee | last post by:
I use asp to develop a web page to read an excel file containing Chinese Character then display it in the web page. Unfortunately, I cant display it!!! it will display (?????????). <META...
1
by: Matt | last post by:
I have an ASP page that calls ASP routines that I created that execute a database query and return the results to a recordset. I then iterate through the recordset and display the data in a table....
2
by: newtophp2000 | last post by:
I created a system DSN for an Excel file and I have been using it for a while. I can read from it as well as update it. (The Excel file includes weekly updates to some records.) Then I tried...
2
by: Reza Solouki | last post by:
Hello, I never had to do anything with office tools programmatically till now(I guess there is first time for everything), so this might be a very silly and simple question for some of you. Any...
4
by: Seok Bee | last post by:
Dear Experts, I have created a script to extract the Event Logs from the system into an excel sheet. The logs are separated into 2 worksheets (Application Log and System Log). After this excel...
6
by: =?Utf-8?B?LnBhdWwu?= | last post by:
how can i write to an excel .xls file using odbc? i've read in several places that its possible but i can't find an example. i have managed to read an excel file using odbc
0
by: minhtran | last post by:
Hi Everyone Lately, I found the code as to read all file from Excel file as ".xls" from Excel before 2007, but does not work for ".xlsx" Excel 2007, Please, any help for me (new hired database...
1
by: DennisBetten | last post by:
First of all, I need to give some credit to Mahesh Chand for providing me with an excellent basis to export data to excel. What does this code do: As the title says, this code is capable of...
2
by: Riak | last post by:
Hellow Helpers: I am doing data entry job manually and data is huge. Now I was told to write/get some sort of program/script which can do this job quickly, otherwise I will loose job. I am good...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.