473,508 Members | 2,303 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with CSV Date column

I'm reading a CSV file with the date colum formatted as "YYMMDD" -"070310"
when viewed in notepad or similar trext editor.
However, in my app, using ODBCReader, the column value becomes "70310"
(integer value). This invalidates my attempt to convert the field into a
date field. I notice that this happened to other columns as well.
Is there a way to keep the original format (or to convert into date field
for this column?

Thanks

Bill
Mar 20 '07 #1
6 2676
Greetings,

Try reading your data this way:

Imports System.Data.OleDb
Imports System.Data

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim da As OleDbDataAdapter, ds As DataSet, conn As OleDbConnection
conn = New OleDbConnection
conn.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;data
source=C:\bin\test1.xls;Extended Properties=Excel 8.0"
da = New OleDbDataAdapter
ds = New DataSet
da.SelectCommand = New OleDbCommand
da.SelectCommand.Connection = conn
da.SelectCommand.CommandText = "Select * From [SubscribersList$]"
da.Fill(ds, "tbl1")
dgrv1.DataSource = ds.Tables("tbl1")
End Sub

My test Excel file included a date field, and the dates displayed correctly
in the datagridview.

hth
Rich

"Bill Nguyen" wrote:
I'm reading a CSV file with the date colum formatted as "YYMMDD" -"070310"
when viewed in notepad or similar trext editor.
However, in my app, using ODBCReader, the column value becomes "70310"
(integer value). This invalidates my attempt to convert the field into a
date field. I notice that this happened to other columns as well.
Is there a way to keep the original format (or to convert into date field
for this column?

Thanks

Bill
Mar 20 '07 #2
Rich;
Thanks but this is propbably not the solution.
I need the data to be in text format (with leading zero) so that I can
convert it into a date field.

Thanks again

Bill
"Rich" <Ri**@discussions.microsoft.comwrote in message
news:26**********************************@microsof t.com...
Greetings,

Try reading your data this way:

Imports System.Data.OleDb
Imports System.Data

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim da As OleDbDataAdapter, ds As DataSet, conn As OleDbConnection
conn = New OleDbConnection
conn.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;data
source=C:\bin\test1.xls;Extended Properties=Excel 8.0"
da = New OleDbDataAdapter
ds = New DataSet
da.SelectCommand = New OleDbCommand
da.SelectCommand.Connection = conn
da.SelectCommand.CommandText = "Select * From [SubscribersList$]"
da.Fill(ds, "tbl1")
dgrv1.DataSource = ds.Tables("tbl1")
End Sub

My test Excel file included a date field, and the dates displayed
correctly
in the datagridview.

hth
Rich

"Bill Nguyen" wrote:
>I'm reading a CSV file with the date colum formatted as "YYMMDD" ->
"070310"
when viewed in notepad or similar trext editor.
However, in my app, using ODBCReader, the column value becomes "70310"
(integer value). This invalidates my attempt to convert the field into a
date field. I notice that this happened to other columns as well.
Is there a way to keep the original format (or to convert into date field
for this column?

Thanks

Bill

Mar 20 '07 #3
VJ
Bill, if you could post a short example of your problem code , along with
only line of data from text file. I will try to help

VJ

"Bill Nguyen" <bi*****************@jaco.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Rich;
Thanks but this is propbably not the solution.
I need the data to be in text format (with leading zero) so that I can
convert it into a date field.

Thanks again

Bill
"Rich" <Ri**@discussions.microsoft.comwrote in message
news:26**********************************@microsof t.com...
>Greetings,

Try reading your data this way:

Imports System.Data.OleDb
Imports System.Data

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim da As OleDbDataAdapter, ds As DataSet, conn As OleDbConnection
conn = New OleDbConnection
conn.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;data
source=C:\bin\test1.xls;Extended Properties=Excel 8.0"
da = New OleDbDataAdapter
ds = New DataSet
da.SelectCommand = New OleDbCommand
da.SelectCommand.Connection = conn
da.SelectCommand.CommandText = "Select * From [SubscribersList$]"
da.Fill(ds, "tbl1")
dgrv1.DataSource = ds.Tables("tbl1")
End Sub

My test Excel file included a date field, and the dates displayed
correctly
in the datagridview.

hth
Rich

"Bill Nguyen" wrote:
>>I'm reading a CSV file with the date colum formatted as "YYMMDD" ->
"070310"
when viewed in notepad or similar trext editor.
However, in my app, using ODBCReader, the column value becomes "70310"
(integer value). This invalidates my attempt to convert the field into a
date field. I notice that this happened to other columns as well.
Is there a way to keep the original format (or to convert into date
field
for this column?

Thanks

Bill


Mar 20 '07 #4
VJ
Ok CDate is the culpirt I think. Please use DateTime.String(....) function
to format, so you can specific to include any format you want.

HTH
VJ

"Bill Nguyen" <bi*****************@jaco.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
VJ;
leading zero in Item(15) was removed during the reading process.

Please review the attached CSV file

Thanks

Bill
------------
Dim csvConnection As OdbcConnection
Dim ConnectionString As String = "Driver={Microsoft Text Driver (*.txt;
*.csv)};Dbq=" & _

mcsvPath & ";"

Try

' Create connection to folder containing CSV file

csvConnection = New OdbcConnection(ConnectionString)

csvConnection.Open()

Dim csvCommand As OdbcCommand

Dim csvReader As OdbcDataReader

Try

' Select all rows from the

csvCommand = csvConnection.CreateCommand()

csvCommand.CommandText = "select * from " & mcsvDoc

csvCommand.CommandType = CommandType.Text

' Use a reader to iterate through the rows

csvReader = csvCommand.ExecuteReader()

If csvReader.Read() Then

Do

If IsDBNull(csvReader.Item(15)) = False Then

mShipDate = csvReader.Item(15)

' mShipdate2 = CDate(csvReader.Item(15))

Else

mShipDate = "NA"

End If

If IsDBNull(csvReader.Item(16)) = False Then

mShipTime = csvReader.Item(16)

Else

mShipTime = "NA"

End If
"VJ" <no***********@yahoo.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>Bill, if you could post a short example of your problem code , along with
only line of data from text file. I will try to help

VJ

"Bill Nguyen" <bi*****************@jaco.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>>Rich;
Thanks but this is propbably not the solution.
I need the data to be in text format (with leading zero) so that I can
convert it into a date field.

Thanks again

Bill
"Rich" <Ri**@discussions.microsoft.comwrote in message
news:26**********************************@micros oft.com...
Greetings,

Try reading your data this way:

Imports System.Data.OleDb
Imports System.Data

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim da As OleDbDataAdapter, ds As DataSet, conn As
OleDbConnection
conn = New OleDbConnection
conn.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;data
source=C:\bin\test1.xls;Extended Properties=Excel 8.0"
da = New OleDbDataAdapter
ds = New DataSet
da.SelectCommand = New OleDbCommand
da.SelectCommand.Connection = conn
da.SelectCommand.CommandText = "Select * From
[SubscribersList$]"
da.Fill(ds, "tbl1")
dgrv1.DataSource = ds.Tables("tbl1")
End Sub

My test Excel file included a date field, and the dates displayed
correctly
in the datagridview.

hth
Rich

"Bill Nguyen" wrote:

I'm reading a CSV file with the date colum formatted as "YYMMDD" ->
"070310"
when viewed in notepad or similar trext editor.
However, in my app, using ODBCReader, the column value becomes "70310"
(integer value). This invalidates my attempt to convert the field into
a
date field. I notice that this happened to other columns as well.
Is there a way to keep the original format (or to convert into date
field
for this column?
>
Thanks
>
Bill
>
>
>





Mar 21 '07 #5
Bill.

I really don't see why Rich solution would not fit.
Dit you try it?

Cor

"Bill Nguyen" <bi*****************@jaco.comschreef in bericht
news:%2****************@TK2MSFTNGP04.phx.gbl...
Rich;
Thanks but this is propbably not the solution.
I need the data to be in text format (with leading zero) so that I can
convert it into a date field.

Thanks again

Bill
"Rich" <Ri**@discussions.microsoft.comwrote in message
news:26**********************************@microsof t.com...
>Greetings,

Try reading your data this way:

Imports System.Data.OleDb
Imports System.Data

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim da As OleDbDataAdapter, ds As DataSet, conn As OleDbConnection
conn = New OleDbConnection
conn.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;data
source=C:\bin\test1.xls;Extended Properties=Excel 8.0"
da = New OleDbDataAdapter
ds = New DataSet
da.SelectCommand = New OleDbCommand
da.SelectCommand.Connection = conn
da.SelectCommand.CommandText = "Select * From [SubscribersList$]"
da.Fill(ds, "tbl1")
dgrv1.DataSource = ds.Tables("tbl1")
End Sub

My test Excel file included a date field, and the dates displayed
correctly
in the datagridview.

hth
Rich

"Bill Nguyen" wrote:
>>I'm reading a CSV file with the date colum formatted as "YYMMDD" ->
"070310"
when viewed in notepad or similar trext editor.
However, in my app, using ODBCReader, the column value becomes "70310"
(integer value). This invalidates my attempt to convert the field into a
date field. I notice that this happened to other columns as well.
Is there a way to keep the original format (or to convert into date
field
for this column?

Thanks

Bill


Mar 21 '07 #6
VJ;
Please forgive my ignorance.
IF the output is "70312" how can I use DateTime function to convert it into
a date of 03/12/2007 ? What's the syntax?

Thanks
Bill
"VJ" <no***********@yahoo.comwrote in message
news:OG****************@TK2MSFTNGP06.phx.gbl...
Ok CDate is the culpirt I think. Please use DateTime.String(....) function
to format, so you can specific to include any format you want.

HTH
VJ

"Bill Nguyen" <bi*****************@jaco.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>VJ;
leading zero in Item(15) was removed during the reading process.

Please review the attached CSV file

Thanks

Bill
------------
Dim csvConnection As OdbcConnection
Dim ConnectionString As String = "Driver={Microsoft Text Driver (*.txt;
*.csv)};Dbq=" & _

mcsvPath & ";"

Try

' Create connection to folder containing CSV file

csvConnection = New OdbcConnection(ConnectionString)

csvConnection.Open()

Dim csvCommand As OdbcCommand

Dim csvReader As OdbcDataReader

Try

' Select all rows from the

csvCommand = csvConnection.CreateCommand()

csvCommand.CommandText = "select * from " & mcsvDoc

csvCommand.CommandType = CommandType.Text

' Use a reader to iterate through the rows

csvReader = csvCommand.ExecuteReader()

If csvReader.Read() Then

Do

If IsDBNull(csvReader.Item(15)) = False Then

mShipDate = csvReader.Item(15)

' mShipdate2 = CDate(csvReader.Item(15))

Else

mShipDate = "NA"

End If

If IsDBNull(csvReader.Item(16)) = False Then

mShipTime = csvReader.Item(16)

Else

mShipTime = "NA"

End If
"VJ" <no***********@yahoo.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>>Bill, if you could post a short example of your problem code , along
with
only line of data from text file. I will try to help

VJ

"Bill Nguyen" <bi*****************@jaco.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl.. .
Rich;
Thanks but this is propbably not the solution.
I need the data to be in text format (with leading zero) so that I can
convert it into a date field.

Thanks again

Bill
"Rich" <Ri**@discussions.microsoft.comwrote in message
news:26**********************************@micro soft.com...
Greetings,
>
Try reading your data this way:
>
Imports System.Data.OleDb
Imports System.Data
>
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim da As OleDbDataAdapter, ds As DataSet, conn As
OleDbConnection
conn = New OleDbConnection
conn.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;data
source=C:\bin\test1.xls;Extended Properties=Excel 8.0"
da = New OleDbDataAdapter
ds = New DataSet
da.SelectCommand = New OleDbCommand
da.SelectCommand.Connection = conn
da.SelectCommand.CommandText = "Select * From
[SubscribersList$]"
da.Fill(ds, "tbl1")
dgrv1.DataSource = ds.Tables("tbl1")
End Sub
>
My test Excel file included a date field, and the dates displayed
correctly
in the datagridview.
>
hth
Rich
>
>
>
"Bill Nguyen" wrote:
>
>I'm reading a CSV file with the date colum formatted as "YYMMDD" ->
>"070310"
>when viewed in notepad or similar trext editor.
>However, in my app, using ODBCReader, the column value becomes
>"70310"
>(integer value). This invalidates my attempt to convert the field
>into a
>date field. I notice that this happened to other columns as well.
>Is there a way to keep the original format (or to convert into date
>field
>for this column?
>>
>Thanks
>>
>Bill
>>
>>
>>





Mar 21 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
7246
by: Lauren Quantrell | last post by:
I have a stored procedure using Convert where the exact same Convert string works in the SELECT portion of the procedure but fails in the WHERE portion. The entire SP is listed below....
9
4280
by: Stefan Bauer | last post by:
Hi NG, we've got a very urgent problem... :( We are importing data with the LOAD utility. The input DATE field data is in the format DDMMYYYY (for days) and MMYYYY (for months). The target...
5
1568
by: Thomas Scheiderich | last post by:
I am having a problem with a Datatable access. This statement apparently works fine: response.write(GetRows.Rows(ktr)(1)) and this statement does not: if e.day.date = GetRows(ktr)(1) then
11
1587
by: Geoff Jones | last post by:
Hi I have a table that has a column with Date types. I am trying to view certain rows in the table using a DataView. Using the filter, I can view the rows with, for example, the date equal...
10
1670
by: Ken | last post by:
I have a form, that when I open it, it shows all items that are due for inspection in the current month and that is overdue. This is shown in continuous view and it has a column that shows overdue...
2
1304
by: z.ghulam | last post by:
At the moment my co uses a spreadsheet to note how many orders each engineer is assigned and this is updated manually. I've thought about transferring this to Access and have thought of two...
4
8313
by: Ken Wigle | last post by:
All, I would be very grateful for any help on this question. I have an application in asp.net 2.0 where I dynamically create a datatable and then bind that to a gridview. Unfortunately, the...
8
2441
by: sara | last post by:
I have a report that runs fine with data. If there is no data, I have its NO Data event sending a MsgBox and cancelling the report. Then it seems I still get the 2501 message on the Open Report...
7
4796
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
2
6562
by: =?Utf-8?B?Y3JlYXZlczA2MjI=?= | last post by:
I have a nested datagrid in a xaml file, the parent datagrid loads the vendor information and the details loads the documents for that vendor in a datagrid. Everything is working fine until I click...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7120
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7494
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1553
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.