我在数据库中上传 Excel 文件时遇到问题...
我正在寻找一个代码,允许我的项目浏览 Excel 文件,然后将所有数据保存在我的数据库中,并自动将其显示在我的数据 GridView 中。
我已经搜索代码大约两天了,我已经尝试了其中一些,但仍然没有找到适合我的问题的代码..
我尝试了这段代码..但它不能正常工作。
Dim conko As System.Data.OleDb.OleDbConnection
Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
Try
Dim fBrowse As New OpenFileDialog
With fBrowse
.Filter = "Excel files(*.xls)|*.xls|All files (*.*)|*.*"
.FilterIndex = 1
.Title = "Import data from Excel file"
End With
If fBrowse.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim fname As String
fname = fBrowse.FileName
Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= " & fname & ";" & " Extended Properties= ""Excel 8.0;HDR=NO;IMEX=1"""
Dim Connection As New System.Data.OleDb.OleDbConnection(ConnectionString)
Connection.Open()
Dim CollectionName As String = "Tables"
Dim dt As DataTable = Connection.GetSchema(CollectionName)
Dim TableRow As DataRow
For Each TableRow In dt.Rows
If TableRow.Item("userlog").ToString.IndexOf("$") = TableRow.Item("userlog").ToString.Length - 1 Then
Console.WriteLine(TableRow.Item("userlog").ToString)
End If
Next
Connection.Close()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
最佳答案
也许您可以引用此 PHP 代码并查看它在 VBA 中的工作原理:
Read excel file and store it to mysql database
好的,我找到了一些其他链接:
http://www.vbaexpress.com/forum/showthread.php?46880-vba-code-import-table-excel-to-mysql
http://forums.mysql.com/read.php?10,100302
http://www.mrexcel.com/forum/excel-questions/734639-mysql-excel-visual-basic-applications.html
关于mysql - 导入excel文件并保存到mysql数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21695765/