用以下语句读取EXCEL表格,却丢失部分行的数据。。。。。
系统windows-xp专业版,office-2003版本
Dim OpenFileDialog As New OpenFileDialog
OpenFileDialog.InitialDirectory = My.Application.Info.DirectoryPath()
OpenFileDialog.Filter = "EXCEL文件(*.xls)|*.xls"
If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
Dim FileName As String = OpenFileDialog.FileName
Dim xbwmsg As String
xbwmsg = MsgBox("文件:'" & FileName & "'你是否确定导入!?", 1)
If xbwmsg <> vbOK Then Exit Sub
Dim MstrConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & FileName & "';Extended Properties=Excel 8.0;"
Dim myDataset As New DataSet
Dim da As New OleDbDataAdapter("select * from [$偏差报告]", MstrConn)
Me.Cursor = Cursors.WaitCursor
PictureBox1.Visible = True
Label21.Visible = True
Label21.Text = "数据读取,请稍候……10%"
Me.Enabled = False
Try
da.Fill(myDataset)
DataGrid1.DataSource = myDataset.Tables.Item(0).DefaultView
Catch ex As Exception
MsgBox(ex.Message.ToString)
Exit Sub
End Try
Label21.Text = "数据读取,请稍候……100%"
这可能和你那几列的空值有极大关系 建议给空处赋0 试试
看着代码是没有问题,你单步调试一下,看看是没有取到数据呀? 还是取到数据显示的时候出问题了呀?
能再详细点吗?