1 Replies - 180 Views - Last Post: 19 February 2018 - 11:17 AM Rate Topic: -----

#1 aspfun   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 48
  • Joined: 16-January 13

Importing Excel file into datatable, all number character is null

Posted 19 February 2018 - 09:40 AM

I learn import a Excel file into a datatable from this link.

http://vb.net-inform...excel_oledb.htm

Second column of Excel file is text type and data stored like "EMP" or "119".

After imported, all number character will not import and left as Null.

How to fix it?

Is This A Good Question/Topic? 0
  • +

Replies To: Importing Excel file into datatable, all number character is null

#2 andrewsw   User is online

  • RequestedRangeNotSatisfiable
  • member icon

Reputation: 6552
  • View blog
  • Posts: 26,562
  • Joined: 12-December 12

Re: Importing Excel file into datatable, all number character is null

Posted 19 February 2018 - 11:17 AM

This is the code that the OP's link refers to:

Imports System.Data
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
                ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim MyConnection As System.Data.OleDb.OleDbConnection
            Dim DtSet As System.Data.DataSet
            Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
            MyConnection = New System.Data.OleDb.OleDbConnection _
            ("provider=Microsoft.Jet.OLEDB.4.0;"  _
            " Data Source='c:\testfile.xls'; " _
             "Extended Properties=Excel 8.0;")
            MyCommand = New System.Data.OleDb.OleDbDataAdapter _
                ("select * from [Sheet1$]", MyConnection)
            MyCommand.TableMappings.Add("Table", "TestTable")
            DtSet = New System.Data.DataSet
            MyCommand.Fill(DtSet)
            DataGridView1.DataSource = DtSet.Tables(0)
            MyConnection.Close()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1