0

What is the best way to read from excel file without losing data? Excel sheet have column formated HH:MM:SS when read it using ADO the time format changed to date and lose actual value:

Sample from excel: enter image description here

After import to grid view: enter image description here

Code:

        Try
        ' Clear the DataGridView and the connection string TextBox
        Dim Datatable As New DataTable("Sometable")
        ' Fill the DataGridView and connection string TextBox
        Using connection As New OleDb.OleDbConnection(Super.Excel_GetConnectionString(txtZDCalc_txtPerPath.Text, txtZDCalc_txtPerPath.Tag))
            connection.Open()
            Using adapter As New OleDb.OleDbDataAdapter("SELECT * FROM [" & cboxZDCalc_Sheet.SelectedItem & "]", connection)
                adapter.Fill(Datatable)
            End Using
        End Using

        Super.ZD_GetEmployees(Datatable)
    Catch ex As Exception
        ' Display any errors
        MessageBox.Show("[" & ex.[GetType]().Name & "] " & ex.Message & ex.StackTrace)
    End Try

Why after import time lose the value ?

KaZzA
  • 104
  • 1
  • 2
  • 9

1 Answers1

0

It sounds as though you want to display the TimeSpan instead of a date. Excel stores the value of the cell as a datetime and uses formatting to control how it is displayed.

What you want to do is to change the datatype of the column in your DataTable to TimeSpan

Have a look at here to find out how to do this: How To Change DataType of a DataColumn in a DataTable?

Community
  • 1
  • 1
Matt Wilko
  • 26,994
  • 10
  • 93
  • 143