我曾尝试将数据从excel导入数据网格视图,但有些数据会在几行中丢失。我在OleDbDataAdapter中搜索并完成了以下更改,例如" Provider = Microsoft.Jet.OLEDB.4.0;数据源= {0};扩展属性=' Excel 8.0; HDR = YES; IMEX = 1&# 39;"但仍然会出现同样的问题。我已经改变了HDR = NO并尝试了。但它也没有成功。
Dim strProvider As String = ConfigurationManager.AppSettings("oledbProviderFin").ToString()
Dim hasHeaders As Boolean = True
Dim connString As [String] = [String].Format(strProvider, txtFilePath.Text, If(hasHeaders, "Yes", "No"))
Dim MyCnn As System.Data.OleDb.OleDbConnection
Dim DSet As System.Data.DataSet
Dim MyCmd As System.Data.OleDb.OleDbDataAdapter
MyCnn = New System.Data.OleDb.OleDbConnection(connString)
MyCmd = New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM " & strSelSheet, MyCnn)
MyCmd.TableMappings.Add("Table", "TestTable")
DSet = New System.Data.DataSet()
MyCmd.Fill(DSet)
TableLines = DSet.Tables(0)
dg_ItemDetails.DataSource = TableLines
MyCnn.Close()
Excel表格: