逐行读取和更新excel文件 [英] Read and update excel file row by row

查看:94
本文介绍了逐行读取和更新excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!我希望能够逐个读取excel文件中的行,并在迭代它们时更新每一行。


如下所示,除了DbDataReader只读取数据,它不能写(显然)。


 command.CommandText = < span style ="color:#a31515">" SELECT * FROM ["  
+ sheet + "]"
;
DbDataReader reader = command.ExecuteReader()

//对于excel文档中的每一行



(reader.Read())
{
  // 1。阅读行数据


  // 2。根据数据做一些计算


  // 3。回写新数据


}

解决方案

你好,


#1。要使用DataReader读取数据,您可以调用reader。 Read()方法


#2。你想进行什么样的计算?


#3。 DbDataReader仅提供只读和仅向前流读取功能。在数据库中修改和更新记录的最佳选择是使用DataSet。


请查看以下文章了解详细信息:

http://support.microsoft.com/kb/316934/


问候


Hello! I would like to be able to read rows from an excel file one by one, and update each row as i iterate through them.

Something like this below, except that DbDataReader only reads data, it is't able to write (obviously).

command.CommandText = "SELECT * FROM ["
 + sheet + "]"
;		
DbDataReader reader = command.ExecuteReader()

//For each row in excel document
while (reader.Read()) {   //1. Read row data
  //2. Do some calculations based on the data
  //3. Write back new data
}

解决方案

Hello,

#1. To read data using DataReader, you could call reader.Read() method.

#2. What kind of calculation do you want to perform?

#3. DbDataReader only provides read-only and forward-only stream reading functionalities. Your best choice of modifying and updating records in database is to use DataSet.

Please take a look at the following article for detail information:
http://support.microsoft.com/kb/316934/

Regards


这篇关于逐行读取和更新excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆