Private Sub readexcel()
Dim cnn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & txtFileName.Text & "; Extended Properties=Excel 12.0;")
Dim oconn As New OleDbCommand("select * from [Sheet1$]", cnn)
cnn.Open()
Dim adp As New OleDbDataAdapter(oconn)
Dim dt As New DataTable()
Dim ds As DataSet
adp.Fill (dt)
dgvExcelData.SelectionMode = DataGridViewSelectionMode.FullRowSelect
dgvExcelData.EditMode = DataGridViewEditMode.EditProgrammatically
dgvExcelData.DataSource = dt
End Sub
上面的代码将 Excel 读取到网格视图中,但是会丢失一些数据。有人能告诉我为什么吗?