本文介绍了如何使用c#从excel表填充值到mysql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! HI朋友。 我有一张excel表,里面有十列和几千行,我需要 导入行在数据库(mysql数据库)中,excel列值需要存储在mysql数据库的不同表中。为此我们正在做的是: - 1-从Excel中读取行使用: - System.Data.OleDb.OleDbConnection sSourceConnection = new System.Data.OleDb.OleDbConnection(excelcon); 2-然后使用以下方法从mysqldatabase插入,更新或选择值: - MYSQL_cmd = new MySqlCommand(query,MYSQL_connection); this .OpenConnection(MYSQL_connection); MYSQL_cmd.ExecuteNonQuery(); 这个 .CloseConnection(MYSQL_connection); 但是问题是触发我需要打开和关闭连接的每个查询,是否正确的方法为千行打开和关闭连接不是一个好的做法我想,请建议.. 谢谢和问候.... 解决方案 按照以下方式执行 创建并打开MYSQL_connection 每行 excel { MYSQL_cmd = new MySqlCommand(query,MYSQL_connection); MYSQL_cmd.ExecuteNonQuery(); } 最后关闭MYSQL_connection HI Friends.I have a excel sheet which have about Ten columns and thousands of rows,i need toimport rows in a database(mysql database),excel column values need to store in different table in mysql database. For that what am doing is : -1- Reading rows from excel using :-System.Data.OleDb.OleDbConnection sSourceConnection = new System.Data.OleDb.OleDbConnection(excelcon);2- then am inserting,updating or selecting values form mysqldatabase by using :- MYSQL_cmd = new MySqlCommand(query, MYSQL_connection); this.OpenConnection(MYSQL_connection); MYSQL_cmd.ExecuteNonQuery(); this.CloseConnection(MYSQL_connection);but the problem is to fire each query i need to open and close connection ,is it proper way to do this for thousand of rows open and close connection is not a good practice i think ,Please suggest..Thanks and Regards.... 解决方案 do as belowcreate and open MYSQL_connectionfor each row in excel{ MYSQL_cmd = new MySqlCommand(query, MYSQL_connection); MYSQL_cmd.ExecuteNonQuery();}finally close the MYSQL_connection 这篇关于如何使用c#从excel表填充值到mysql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-23 21:28