使用c#从excel读取数据 [英] read data from excel using c#

查看:335
本文介绍了使用c#从excel读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从第7行到第11行从Excel工作表读取数据然后在sql表中插入?

how can i read data from an excel sheet from row 7 to row 11 and insert then in sql table?

推荐答案

OleDbConnection Con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Your xcel path + ";Extended Properties=Excel 8.0");

               Con.Open();
               try
               {
                           DataSet myDataSet = new DataSet();
                   OleDbDataAdapter myCommand = new OleDbDataAdapter(" SELECT * FROM [Sheet1


,Con);
myCommand.Fill(myDataSet);
string value = myDataSet.Tables [ 0 ]。行[ 6 ]。IttemArray [ 10 ]。tostring();


Con.Close();


}
catch (Exception ex)
{
MessageBox.Show(< span class =code-string> 验证你的excel文件);
}
", Con); myCommand.Fill(myDataSet); string value=myDataSet.Tables[0].Rows[6].IttemArray[10].tostring(); Con.Close(); } catch (Exception ex) { MessageBox.Show("verify ur excel file"); }


请参阅此MSDN文章 [ ^ ]。


这篇关于使用c#从excel读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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