最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
vb.net 数据导入excel代码
时间:2022-06-25 05:35:22 编辑:袖梨 来源:一聚教程网
vb.net 数据导入excel代码
这是一款简单的由vb.net把数据库教程的数据导入到execel实例哦,如果你正在找相关的.net把数据导入到数据表的话,这是一款完整的可用代码。
imports system.data
imports system.data.sqlclient
public class form1
dim app as new excel.application
dim exbook as excel.workbook
dim exsheet as excel.worksheet
dim exrange as excel.range
private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click
exbook = app.workbooks.open("d:www.111com.netc.xls")
exsheet = exbook.sheets(1)
dim myconnection as new sqlconnection("data source=192.168.0.1;initial catalog=test;user id=sa;password=abc")
dim mycommand as sqlcommand = new sqlcommand()
myconnection.open()
mycommand.connection = myconnection
mycommand.commandtext = "select un001,un002,un003 from bcun"
mycommand.commandtype = commandtype.text
dim myreader as sqldatareader = mycommand.executereader
dim i as integer = 1
do while myreader.read()
exsheet.cells(i, 1) = myreader.getstring(0)
exsheet.cells(i, 2) = myreader.getstring(1)
exsheet.cells(i, 3) = myreader.getstring(2)
i = i + 1
loop
myreader.close()
myconnection.close()
exbook.save()
exbook.close()
app.workbooks.close()
app.quit()
mycommand.connection.close()
end sub
end class
/*
请注意在引用中添加com组件:microsoft excel 11.0 object library(不一定是11.0的,由你用的excel版本来定)
相关文章
- 死亡搁浅2次要订单No.100 将拆解的步枪送到独行指挥官手上全流程攻略 09-06
- 死亡搁浅2怎么开启照明 闪光灯开启方法 09-06
- 超级忍反攻的斩击怎么下载 完整中文版获取指南 09-06
- 死亡搁浅2怎么使用VR培训室 09-06
- 超级忍反攻的斩击有手机版吗 移动端游玩指南 09-06
- 死亡搁浅2怎么提高波特等级 提高波特等级的方法 09-06