469,267 Members | 979 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,267 developers. It's quick & easy.

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 4187
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

Post your reply

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

Similar topics

reply views Thread by Phil Perrin | last post: by
6 posts views Thread by jw | last post: by
2 posts views Thread by madeleine | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.