OLEDB Excel Connection with VB.NET

When i pull data from an excel sheet through oledb (select * from sheet name, and extended properties are no on header and 1 on imex) i get my dates in a numeric format... how can i correct this... its killing me!

[264 byte] By [BenMolk] at [2008-1-7]
# 1

Hi,

Here is simple code example. It reads date value from excel sheet. Do you convert value to DateTime object ? If you have further question, please post your code about reading date value from excel sheet. Hope this can help you.

Code Snippet

Dim cmd As OleDbDataAdapter

Dim ds As New DataSet()

Dim cn As OleDbConnection

cn = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;" + "data source=C:\book.xls;Extended Properties=Excel 8.0;")

cmd = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", cn)

cn.Open()

cmd.Fill(ds, "Table1")

cn.Close()

Me.dataGridView1.DataSource = ds

Me.dataGridView1.DataMember = "Table1"

Dim dt1 As DateTime = DirectCast(dataGridView1.Rows(1).Cells(0).Value, DateTime)

Thanks for your question

RiquelDong–MSFT at 2007-10-2 > top of Msdn Tech,Visual Basic,Visual Basic Language...