473,396 Members | 1,891 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,396 software developers and data experts.

Import Excel Sheet datas into mysql

7
Hi,

I have a C#.net application in which i have read the datas from excel sheet and displayed in a datagrid in my Aspx form.

The code is here

private void Button2_Click(object sender, System.EventArgs e)
{

try
{
string strConnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Salary.xls;Extended Properties=""Excel 8.0;HDR=YES;""";
OleDbConnection conn = new OleDbConnection(strConnection);
//conn.Open();
OleDbCommand command = new OleDbCommand("SELECT * FROM [Sheet1$]", conn);
// command.Connection = conn;
// command.CommandType = CommandType.Text;
// command.CommandText = "SELECT * FROM [Sheet1]";
OleDbDataAdapter da = new OleDbDataAdapter(command);
DataSet ds = new DataSet();
//DataTable dt = new DataTable();
conn.Open();
da.Fill(ds, "EmpSal");
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
//da.Fill(dt);
conn.Close();
lblError.Text="The Excel sheet has been read";

//return dt;
}
catch (Exception ex)
{
Response.Write( ex.Message);
//return null;
}


}

the thing is that i have to upload the datas into the mysql database table. can anybody pls help me with the C#.net code. i need to use only mysql database.(coz we r using mysql db in our project)

Regards
Vijay.
May 12 '07 #1
6 4453
vj83
7
Hi,

I have a C#.net application in which i have read the datas from excel sheet and displayed in a datagrid in my Aspx form.

The code is here

private void Button2_Click(object sender, System.EventArgs e)
{

try
{
string strConnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Salary.xls;Extended Properties=""Excel 8.0;HDR=YES;""";
OleDbConnection conn = new OleDbConnection(strConnection);
//conn.Open();
OleDbCommand command = new OleDbCommand("SELECT * FROM [Sheet1$]", conn);
// command.Connection = conn;
// command.CommandType = CommandType.Text;
// command.CommandText = "SELECT * FROM [Sheet1]";
OleDbDataAdapter da = new OleDbDataAdapter(command);
DataSet ds = new DataSet();
//DataTable dt = new DataTable();
conn.Open();
da.Fill(ds, "EmpSal");
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
//da.Fill(dt);
conn.Close();
lblError.Text="The Excel sheet has been read";

//return dt;
}
catch (Exception ex)
{
Response.Write( ex.Message);
//return null;
}


}

the thing is that i have to upload the datas into the mysql database table. can anybody pls help me with the C#.net code. i need to use only mysql database.(coz we r using mysql db in our project)

Regards
Vijay.
May 15 '07 #2
vj83
7
Hi,

I have a C#.net application in which i have read the datas from excel sheet and displayed in a datagrid in my Aspx form.

The code is here
Expand|Select|Wrap|Line Numbers
  1. private void Button2_Click(object sender, System.EventArgs e)
  2. {
  3.  
  4. try
  5. {
  6. string strConnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Salary.xls;Extended Properties=""Excel 8.0;HDR=YES;""";
  7. OleDbConnection conn = new OleDbConnection(strConnection);
  8. //conn.Open();
  9. OleDbCommand command = new OleDbCommand("SELECT * FROM [Sheet1$]", conn);
  10. // command.Connection = conn;
  11. // command.CommandType = CommandType.Text;
  12. // command.CommandText = "SELECT * FROM [Sheet1]";
  13. OleDbDataAdapter da = new OleDbDataAdapter(command);
  14. DataSet ds = new DataSet();
  15. //DataTable dt = new DataTable();
  16. conn.Open();
  17. da.Fill(ds, "EmpSal");
  18. DataGrid1.DataSource=ds;
  19. DataGrid1.DataBind();
  20. //da.Fill(dt);
  21. conn.Close();
  22. lblError.Text="The Excel sheet has been read";
  23.  
  24. //return dt;
  25. }
  26. catch (Exception ex)
  27. {
  28. Response.Write( ex.Message);
  29. //return null;
  30. }
  31.  
  32.  
  33. }
  34.  
the thing is that i have to upload the datas into the mysql database table. can anybody pls help me with the C#.net code. i need to use only mysql database.(coz we r using mysql db in our project)

Regards
Vijay.
May 15 '07 #3
kenobewan
4,871 Expert 4TB
Here is an article that may help:
Read Excel files from ASP.NET
May 15 '07 #4
Atli
5,058 Expert 4TB
Moved to the .Net forums. And I edited the title.

MODERATOR
May 15 '07 #5
TRScheel
638 Expert 512MB
Hi,

I have a C#.net application in which i have read the datas from excel sheet and displayed in a datagrid in my Aspx form.

The code is here
Expand|Select|Wrap|Line Numbers
  1. private void Button2_Click(object sender, System.EventArgs e)
  2. {
  3.  
  4. try
  5. {
  6. string strConnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Salary.xls;Extended Properties=""Excel 8.0;HDR=YES;""";
  7. OleDbConnection conn = new OleDbConnection(strConnection);
  8. //conn.Open();
  9. OleDbCommand command = new OleDbCommand("SELECT * FROM [Sheet1$]", conn);
  10. // command.Connection = conn;
  11. // command.CommandType = CommandType.Text;
  12. // command.CommandText = "SELECT * FROM [Sheet1]";
  13. OleDbDataAdapter da = new OleDbDataAdapter(command);
  14. DataSet ds = new DataSet();
  15. //DataTable dt = new DataTable();
  16. conn.Open();
  17. da.Fill(ds, "EmpSal");
  18. DataGrid1.DataSource=ds;
  19. DataGrid1.DataBind();
  20. //da.Fill(dt);
  21. conn.Close();
  22. lblError.Text="The Excel sheet has been read";
  23.  
  24. //return dt;
  25. }
  26. catch (Exception ex)
  27. {
  28. Response.Write( ex.Message);
  29. //return null;
  30. }
  31.  
  32.  
  33. }
  34.  
the thing is that i have to upload the datas into the mysql database table. can anybody pls help me with the C#.net code. i need to use only mysql database.(coz we r using mysql db in our project)

Regards
Vijay.
Couldnt you just change your SELECT * FROM [SHEET1] to something like UPDATE [SHEET1] ... and fill in the rest with the needed sql statement to update it?

Also, on a side note, I would consider refactoring your code a bit. You are mixing a lot of elements into one snippet.
May 15 '07 #6
vj83
7
Hi,

I have a C#.net application in which i have read the datas from excel sheet and displayed in a datagrid in my Aspx form.

The code is here

private void Button2_Click(object sender, System.EventArgs e)
{

try
{
string strConnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Salary.xls;Extended Properties=""Excel 8.0;HDR=YES;""";
OleDbConnection conn = new OleDbConnection(strConnection);
//conn.Open();
OleDbCommand command = new OleDbCommand("SELECT * FROM [Sheet1$]", conn);
// command.Connection = conn;
// command.CommandType = CommandType.Text;
// command.CommandText = "SELECT * FROM [Sheet1]";
OleDbDataAdapter da = new OleDbDataAdapter(command);
DataSet ds = new DataSet();
//DataTable dt = new DataTable();
conn.Open();
da.Fill(ds, "EmpSal");
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
//da.Fill(dt);
conn.Close();
lblError.Text="The Excel sheet has been read";

//return dt;
}
catch (Exception ex)
{
Response.Write( ex.Message);
//return null;
}


}

the thing is that i have to upload the datas into the mysql database table. can anybody pls help me with the C#.net code. i need to use only mysql database.(coz we r using mysql db in our project)

Regards
Vijay.
May 16 '07 #7

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

Similar topics

0
by: Phil Perrin | last post by:
------=_NextPart_000_0001_01C3663D.5E3EAD70 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit I'm a relative newbie to MySql, and I've got a small project I'm working...
8
by: Nick M | last post by:
Hello All, Excellent info here Thanks! I am very new to using access in general and I am on a learning curve. I'm trying to import an excel workbook (with worksheets) into an access db via a...
6
by: jw | last post by:
i have datas in an excel file like this: names surnames jack white smith black marry brown how can i read these datas for ex i know that names in the cell A1 and surnames is...
1
by: Peter Stojkovic | last post by:
I am importing data from an EXCEL XLS-File via OLEDB-Provider The command is SELECT * from Everything works fine if the first sheet is named sheet1 But sometimes the name is not known...
2
by: madeleine | last post by:
I'm hoping the answer to this is that I'm just doing something silly, but I'm really scratching my head over this one. I'm importing data from multiple workbooks, each workbook has a sheet called...
1
by: vj83 | last post by:
Hi, I have a C#.net application in which i have read the datas from excel sheet and displayed in a datagrid in my Aspx form. The code is here private void Button2_Click(object sender,...
5
by: Sport Girl | last post by:
Hi everybody. I am new in PERL language and working in it since little hours, actually i am still a trainee and i need help please. In fact, i need a script in PERL that enables me to retrieve...
1
by: Sport Girl | last post by:
Hi everybody , i have the task of developing in Perl a script that retrieves data from 3 tables ( bugs, profiles, products) from a MySQL database called bugs and display them in an excel sheet...
7
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.