我正在尝试将特定数据从 excel 导入数据网格,并能够使用以下查询将所有 excel 数据导入数据网格
从 [Allinone$] 中选择 *
也在下面查询也工作文件
从 [Allinone$] 中选择状态
但下面的查询不起作用
从 [Allinone$] 中选择 part.desc
我的代码在下面
Try
Dim filename As String
Dim ofd As New OpenFileDialog
ofd.Title = "Please select the excel which you want to import"
If ofd.ShowDialog = DialogResult.OK Then
filename = ofd.FileName
Dim strin As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & filename & ";Extended Properties=""Excel 12.0;HDR=YES"";"
Dim con As OleDbConnection = New OleDbConnection(strin)
If con.State = ConnectionState.Closed Then
con.Open()
Dim command As OleDbCommand = New OleDbCommand()
command.CommandText = "Select status from [Allinone$]"
command.Connection = con
Dim adapter As OleDbDataAdapter = New OleDbDataAdapter()
adapter.SelectCommand = command
Dim dt As New DataSet
adapter.Fill(dt, "AllTickets")
DataGridView1.DataSource = dt.Tables(0)
End If
Else
MsgBox("Havn't selected the file,Form Gonna end now")
Exit Sub
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
我希望标题中的 .(dot) 可能有问题..有什么办法可以解决它..