我的datagridview由excel工作表填充(通过使用select * from $ Sheet1),大多数值都插入到datagridview中(大多数是字符串),但只有整数值被取消
无效查询示例
这就是我填充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
我该如何解决?