选择查询填充datagridview但是NULLS整数,为什么?

时间:2015-07-10 00:12:23

标签: vb.net excel datagridview

我的datagridview由excel工作表填充(通过使用select * from $ Sheet1),大多数值都插入到datagridview中(大多数是字符串),但只有整数值被取消

first image

无效查询示例

second image

这就是我填充datagridview的方式

Private Sub btnimportStdntList_Click(sender As Object, e As EventArgs) Handles btnimportStdntList.Click
        OpenFileDialog1.Title = "Please Select the excel file with the list of question"
        OpenFileDialog1.FileName = "listofquestion.xls"
        OpenFileDialog1.Filter = "Excel Sheet(*.xls)|*.xls|All Files(*.*)|*.*"
        OpenFileDialog1.InitialDirectory = "C:temp"
        OpenFileDialog1.ShowDialog()
    End Sub
    Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
        Try
            Dim strm As System.IO.Stream
            strm = OpenFileDialog1.OpenFile()
            txtQuestionList.Text = OpenFileDialog1.FileName.ToString()
            cn = New OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + txtQuestionList.Text + "';Extended Properties=Excel 8.0;")
            cn.Open()
            FillDataGridView("SELECT * FROM [Sheet1$]")
        Catch myerror As Exception
            MessageBox.Show(myerror.Message)
        Finally
            cn.Close()
        End Try
    End Sub
    Private Sub FillDataGridView(ByVal Query As String)
        da = New OleDbDataAdapter(Query, cn)
        dt = New DataTable
        da.Fill(dt)
        With DataGridView1
            .DataSource = dt
        End With
    End Sub 

我该如何解决?

0 个答案:

没有答案