user3138788
user3138788

Reputation: 53

VB.NET Datagrid view not showing a complete column of Integer data

I am working on uploading a excel data to a datagrid view. The excel contains data about asset mapping (asset ID, EmpID1, EmpID2, Project#, etc..,) for a particular project (Some assets may be tagged to more than 1 associate, so I've 2 EmpId field & the second one may have null value). Here I am just trying to query (select *..) the excel & place it in a datatable (which I need for latter usage) & finally showing it in datagrid view. Though the data export happens fine, I am observing a peculiar behavior in vb.net

1) The EmpID2 column does not show any data (its fully blank), if there is no data within first 10 rows. i.e., if first 10 rows are blank for this column, then the entire column is blank in data grid view.

2) If at least one row has value (even if I manually add a junk digit) within first 10 rows, then I can see the data for rest of the rows are updated properly.

code snippet:

    Dim query_Assetsmapping As String = "select * from [sheet1$]"
    Dim MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=Asset_Mapping.xls; Extended Properties=Excel 8.0")
    Dim MyCommand = New System.Data.OleDb.OleDbDataAdapter(query_Assetsmapping, MyConnection)
    Dim DtSet = New System.Data.DataTable
    MyCommand.Fill(DtSet)
    MyConnection.Close()
    DataGridView1.DataSource = DtSet.tables(0)

I don't see any datatype problem, coz I am just exporting the data from excel to data table without specifying or converting datatypes.

Help me in understanding, if anything needs to be explicitly specified for the datagrid view property, so I can show the entire data in the data grid.

Note: The EmpId field is a 6 digit number.

Upvotes: 1

Views: 1692

Answers (1)

Jadeja RJ
Jadeja RJ

Reputation: 1014

Just change your connection string

Dim MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=Asset_Mapping.xls;Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'")

Upvotes: 1

Related Questions