1
votes

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

Please verifiy my source if missing some source?

Thank You. Love .Net

2

2 Answers

0
votes

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")
0
votes

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?