473,545 Members | 2,084 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 2683
Greetings,

Try reading your data this way:

Imports System.Data.Ole Db
Imports System.Data

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim da As OleDbDataAdapte r, ds As DataSet, conn As OleDbConnection
conn = New OleDbConnection
conn.Connection String = "provider=Micro soft.Jet.OLEDB. 4.0;data
source=C:\bin\t est1.xls;Extend ed Properties=Exce l 8.0"
da = New OleDbDataAdapte r
ds = New DataSet
da.SelectComman d = New OleDbCommand
da.SelectComman d.Connection = conn
da.SelectComman d.CommandText = "Select * From [SubscribersList $]"
da.Fill(ds, "tbl1")
dgrv1.DataSourc e = 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**@discussio ns.microsoft.co mwrote in message
news:26******** *************** ***********@mic rosoft.com...
Greetings,

Try reading your data this way:

Imports System.Data.Ole Db
Imports System.Data

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim da As OleDbDataAdapte r, ds As DataSet, conn As OleDbConnection
conn = New OleDbConnection
conn.Connection String = "provider=Micro soft.Jet.OLEDB. 4.0;data
source=C:\bin\t est1.xls;Extend ed Properties=Exce l 8.0"
da = New OleDbDataAdapte r
ds = New DataSet
da.SelectComman d = New OleDbCommand
da.SelectComman d.Connection = conn
da.SelectComman d.CommandText = "Select * From [SubscribersList $]"
da.Fill(ds, "tbl1")
dgrv1.DataSourc e = 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.comw rote in message
news:%2******** ********@TK2MSF TNGP04.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**@discussio ns.microsoft.co mwrote in message
news:26******** *************** ***********@mic rosoft.com...
>Greetings,

Try reading your data this way:

Imports System.Data.Ole Db
Imports System.Data

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventAr gs) Handles Button1.Click
Dim da As OleDbDataAdapte r, ds As DataSet, conn As OleDbConnection
conn = New OleDbConnection
conn.Connection String = "provider=Micro soft.Jet.OLEDB. 4.0;data
source=C:\bin\ test1.xls;Exten ded Properties=Exce l 8.0"
da = New OleDbDataAdapte r
ds = New DataSet
da.SelectComman d = New OleDbCommand
da.SelectComman d.Connection = conn
da.SelectComman d.CommandText = "Select * From [SubscribersList $]"
da.Fill(ds, "tbl1")
dgrv1.DataSourc e = 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.comw rote in message
news:%2******** ********@TK2MSF TNGP03.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 ConnectionStrin g As String = "Driver={Micros oft Text Driver (*.txt;
*.csv)};Dbq=" & _

mcsvPath & ";"

Try

' Create connection to folder containing CSV file

csvConnection = New OdbcConnection( ConnectionStrin g)

csvConnection.O pen()

Dim csvCommand As OdbcCommand

Dim csvReader As OdbcDataReader

Try

' Select all rows from the

csvCommand = csvConnection.C reateCommand()

csvCommand.Comm andText = "select * from " & mcsvDoc

csvCommand.Comm andType = CommandType.Tex t

' Use a reader to iterate through the rows

csvReader = csvCommand.Exec uteReader()

If csvReader.Read( ) Then

Do

If IsDBNull(csvRea der.Item(15)) = False Then

mShipDate = csvReader.Item( 15)

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

Else

mShipDate = "NA"

End If

If IsDBNull(csvRea der.Item(16)) = False Then

mShipTime = csvReader.Item( 16)

Else

mShipTime = "NA"

End If
"VJ" <no***********@ yahoo.comwrote in message
news:%2******** ********@TK2MSF TNGP04.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.comw rote in message
news:%2******* *********@TK2MS FTNGP04.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**@discussio ns.microsoft.co mwrote in message
news:26****** *************** *************@m icrosoft.com...
Greetings,

Try reading your data this way:

Imports System.Data.Ole Db
Imports System.Data

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.Event Args) Handles Button1.Click
Dim da As OleDbDataAdapte r, ds As DataSet, conn As
OleDbConnect ion
conn = New OleDbConnection
conn.Connection String = "provider=Micro soft.Jet.OLEDB. 4.0;data
source=C:\bi n\test1.xls;Ext ended Properties=Exce l 8.0"
da = New OleDbDataAdapte r
ds = New DataSet
da.SelectComman d = New OleDbCommand
da.SelectComman d.Connection = conn
da.SelectComman d.CommandText = "Select * From
[SubscribersList $]"
da.Fill(ds, "tbl1")
dgrv1.DataSourc e = 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.coms chreef in bericht
news:%2******** ********@TK2MSF TNGP04.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**@discussio ns.microsoft.co mwrote in message
news:26******** *************** ***********@mic rosoft.com...
>Greetings,

Try reading your data this way:

Imports System.Data.Ole Db
Imports System.Data

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventAr gs) Handles Button1.Click
Dim da As OleDbDataAdapte r, ds As DataSet, conn As OleDbConnection
conn = New OleDbConnection
conn.Connection String = "provider=Micro soft.Jet.OLEDB. 4.0;data
source=C:\bin\ test1.xls;Exten ded Properties=Exce l 8.0"
da = New OleDbDataAdapte r
ds = New DataSet
da.SelectComman d = New OleDbCommand
da.SelectComman d.Connection = conn
da.SelectComman d.CommandText = "Select * From [SubscribersList $]"
da.Fill(ds, "tbl1")
dgrv1.DataSourc e = 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******** ********@TK2MSF TNGP06.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.comw rote in message
news:%2******** ********@TK2MSF TNGP03.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 ConnectionStrin g As String = "Driver={Micros oft Text Driver (*.txt;
*.csv)};Dbq= " & _

mcsvPath & ";"

Try

' Create connection to folder containing CSV file

csvConnectio n = New OdbcConnection( ConnectionStrin g)

csvConnection. Open()

Dim csvCommand As OdbcCommand

Dim csvReader As OdbcDataReader

Try

' Select all rows from the

csvCommand = csvConnection.C reateCommand()

csvCommand.Com mandText = "select * from " & mcsvDoc

csvCommand.Com mandType = CommandType.Tex t

' Use a reader to iterate through the rows

csvReader = csvCommand.Exec uteReader()

If csvReader.Read( ) Then

Do

If IsDBNull(csvRea der.Item(15)) = False Then

mShipDate = csvReader.Item( 15)

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

Else

mShipDate = "NA"

End If

If IsDBNull(csvRea der.Item(16)) = False Then

mShipTime = csvReader.Item( 16)

Else

mShipTime = "NA"

End If
"VJ" <no***********@ yahoo.comwrote in message
news:%2******* *********@TK2MS FTNGP04.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.comw rote in message
news:%2****** **********@TK2M SFTNGP04.phx.gb l...
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**@discussio ns.microsoft.co mwrote in message
news:26***** *************** **************@ microsoft.com.. .
Greetings ,
>
Try reading your data this way:
>
Imports System.Data.Ole Db
Imports System.Data
>
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.Even tArgs) Handles Button1.Click
Dim da As OleDbDataAdapte r, ds As DataSet, conn As
OleDbConnec tion
conn = New OleDbConnection
conn.Connection String = "provider=Micro soft.Jet.OLEDB. 4.0;data
source=C:\b in\test1.xls;Ex tended Properties=Exce l 8.0"
da = New OleDbDataAdapte r
ds = New DataSet
da.SelectComman d = New OleDbCommand
da.SelectComman d.Connection = conn
da.SelectComman d.CommandText = "Select * From
[SubscribersList $]"
da.Fill(ds, "tbl1")
dgrv1.DataSourc e = 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
7251
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. Specifically, I have a problem with this portion in the WHERE clause: DATEADD(Day,tblMyEventTableName.ReminderDays, @DateNow) Between...
9
4288
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 data format is european DD.MM.YYYY (for days) and 01.MM.YYYY (for months). The input format is not recognizable as a DATE input to a DB2 LOAD for
5
1570
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
1592
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 to something e.g. vue.RowFilter = "Date = #01/01/03#"
10
1671
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 months. So if it was November it would show all the assets due in November with a "0" in the Overdue column. And if there happen to be some...
2
1307
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 possible ways, 1 is clearly better then the other but goes beyond my Access knowledge. If anyone cares to have a read I'd appreciate any feedback. Each...
4
8316
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 date column always shows the date and time while I just want the short date. I have tried applying a format string {0:d} but to no avail. I saw a...
8
2443
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 command, even though I have the code to trap Err 2501 (from many postings - all looked the same to me) on the button the user pressed to get the...
7
4803
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 expandable row, the hidden row is made visible with css. The problem is when i sort the rows, the hidden rows get sorted as well which i don't want and want...
2
6567
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 in the child datagrid and then go to the combobox and choose another vendor. When the new vendor is loaded nothing shows in the datagrid but the...
0
7405
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7760
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5975
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5334
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3455
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1887
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 we have to send another system
1
1019
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
709
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.