Jun 5

odbc 读写 Excel 晴

admin365 , 02:54 , Excel , 评论(0) , 引用(0) , 阅读(87) , Via 本站原创 | |



[转载]

odbc 读写 Excel

 作者:阿拉伯顶峰 来源:http://www.cnblogs.com/0hi/archive/2008/02/26/1082012.html 
  对Excel的操作时很频繁的,用哪种方法更合适,那就看系统的应用了。
下面应用odbc读写Excel特别方便、简单。 便随笔随笔更多好方法还望高手留笔 首先当然要引用using System.Data.Odbc 名称空间。 具体读Excel方法:
  
  OdbcConnection Connnection = new OdbcConnection(); Connnection.ConnectionString = "Driver={Microsoft Excel Driver (*.xls)};DBQ=" + itemFile; OdbcCommand cmd = new OdbcCommand(); cmd.Connection = Connnection; cmd.CommandText = "SELECT * FROM [Sheet1$]"; OdbcDataAdapter oda = new OdbcDataAdapter(cmd); DataTable dt = new DataTable(); oda.Fill(dt); Connnection.Close(); 
 
 具体写Excel 方法: 
  
  OdbcConnection Connnection = new OdbcConnection(); Connnection.ConnectionString = "Driver={Microsoft Excel Driver (*.xls)};Readonly=0;DBQ=" + itemFile; OdbcCommand cmd = new OdbcCommand(); cmd.Connection = Connnection; Connnection.Open(); cmd.CommandText="Insert into [Sheet1$] (name,password) values ('admin','admin')"; cmd.ExecuteNonQuery(); Connnection.Close(); 
 
  如果更新的话,CommandText值改成Update语句就可以了。 觉得值得注意的地方:执行写操作时,ConnectionString要设置Excel文件可写。 
  

[转载]原文链接: http://mcs.szu.edu.cn/Article/39541

百度搜索:Excel
Google搜索:Excel
雅虎搜索:Excel
SOSO搜索:Excel



Tags:
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]