1

I'm developing my app in VB.Net with the source below but the problem that I got, was the data not displayed completely in DataGridView.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim conn As OleDb.OleDbConnection
    Dim dta As OleDb.OleDbDataAdapter
    Dim dts As DataSet
    Dim excelpath As String

    Dim ExcelQuery As String = "Select * From [IOT_NOVA$B12:S257]"

    Try

        If TextBox1.Text = "" Then
            MsgBox("Please select Excel file to upload!", vbExclamation)
            Exit Sub
        End If

        excelpath = TextBox1.Text
        conn = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelpath + ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1';")
        dta = New OleDb.OleDbDataAdapter(ExcelQuery, conn)

        DtSet = New DataTable
        dta.Fill(DtSet)


        DataGridView1.DataSource = DtSet
        
        conn.Close()
        conn.Dispose()

    Catch ex As Exception
        MsgBox(ex.Message, vbCritical)
    End Try

End Sub
Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220
JVYLY
  • 11
  • 4

2 Answers2

0

You need to set the table name when setting the DataSource of the DataGridview.

DataGridView1.DataSource = DtSet.Tables(0)

or

DataGridView1.DataSource = DtSet.Tables("IOT_NOVA")
Karen Payne
  • 4,341
  • 2
  • 14
  • 31
  • Set or not the table name but the result is same. The problem was, the data displayed in datagridview but missing some data that with more than 1000 caracteres/digits. – JVYLY Apr 06 '16 at 06:51
  • Could anyone help me on this issue? – JVYLY Aug 10 '18 at 02:05
  • Is it possible to upload this Excel file to say Microsoft OneDrive (it's free) if the data is not sensitive data. I can then give it a try to see what the issue may be. – Karen Payne Aug 10 '18 at 10:08
  • The data is sensitive. Could you please download it via google drive that i linked here. – JVYLY Aug 21 '18 at 06:38
  • If you supply a link to Google Drive I can look at it. – Karen Payne Aug 21 '18 at 10:24
0

You may have (had) an issue with default column box sizes. See this question: How to set max length of datagridview column Edit: found another issue - excel data driver is buggy. Look far down in this thread: How do I create an Excel (.XLS and .XLSX) file in C# without installing Microsoft Office?