您的位置:首页 > 数据库

[VB.NET]如何导入excel表格到数据库

2008-12-28 11:36 295 查看



<script type="text/javascript"><!--
google_ad_client = "pub-8333940862668978";
/* 728x90, 创建于 08-11-30 */
google_ad_slot = "4485230109";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

如何导入excel表格到数据库
实现通过vb.net界面操作,找到excel文件后,点击导入按纽,可以把excel文件导入到数据库
__________________________________________________________________________
1. Find excel file.
2. Use VB.NET to make a datasource from excel, then update database.
__________________________________________________________________________
能不能再详细一点啊
具体怎么操作啊
__________________________________________________________________________
vb.net 的dataset数据库有从execl中导入数据功能,你看一下帮助吧,我没用过,但肯定是有的.
__________________________________________________________________________
-----------------------我这里有一段代码是导入ACCESS的,记得将SQL语句仲的SELECT * 修改成SELECT 字段即可。另外想问一下如何将导入默认为第一个表?即EXCEL无论第一个表的名称为什么都可以导入
Dim conExcel = New OleDb.OleDbConnection()
Try
Dim openFile = New OpenFileDialog() ''//打开文件对话框。
openFile.Filter = ("Excel 文件(*.xls) |*.xls") ''//后缀名。
If openFile.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim filename As String = openFile.FileName
Dim index As Integer = filename.LastIndexOf("//") ''截取文件的名字
filename = filename.Substring(index + 1)
conExcel.ConnectionString = " Provider=Microsoft.Jet.OleDb.4.0;Data Source=数据库.mdb;Persist Security Info=false;" ''"Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + Application.StartupPath + "//Appdata.mdb"

''将excel导入access

Dim sql As String = "insert into info select * from [Excel 8.0;database=" + filename + "].[导入格式$] where studid not IN (select studid from info)"
Dim com As OleDb.OleDbCommand = New OleDb.OleDbCommand(sql, conExcel)
conExcel.Open()
com.ExecuteNonQuery()
End If
Catch ex As Exception
MessageBox.Show(ex.ToString())
Finally
conExcel.Close()
MessageBox.Show("导入数据成功", "导入数据", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
------------------------
__________________________________________________________________________
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐