Saturday, May 22, 2010

Insert excel datas in mysql database?

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.

Insert excel datas in mysql database?
your oledbconnection needs to be a mysqlconnection. take a look at this site:


http://dev.mysql.com/doc/refman/5.1/en/c...

online survey

No comments:

Post a Comment