Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

writeline bad character pos 1,1

Status
Not open for further replies.

GROKING

Programmer
Mar 8, 2005
26
US

Hello,

I have a VB.NET program that converts an XML file to CSV.
When I try to import the CSV into Oracle or even Access it chokes on the first row, but does import the remaining rows into a table.
It seems there is a type conversion character in position column 1,row 1, that is not visible when opening the file in Linux VI or notepad.

Here is my code for the writeline-
+++++++++++++++++++++
While Not m_xmlr.EOF
myfile.WriteLine(FileDate3 & "," & campaignValue & "," & kwsiteValue & "," & kwsitetypeValue & "," & campstatusValue & "," & impsValue & "," & clicksValue & "," & cost & "," & pos)
End While
+++++++++++++++++++++

do i need a vbcrlf or something like that at the end of the string??
any way to find out what the character is?

Any ideas are greatly appreciated.

thanks
Ron-Netshops.com


 
What is the datatype of [tt]FileDate3[/tt], and does it overload the [tt]ToString[/tt] method?

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 

Public FileDate2 As Date

ReportJob.startDate = DateTimePicker1.Value.Date
FileDate2 = ReportJob.startDate.Date

This code is within the same class but in a procedure before the writeline code.

I can see already that I could just do this:
FileDate2 = DateTimePicker1.Value.Date

But will this solve it. I can test and advise.

As I mentioned, this only occurs on the first position, all subsequent FileDate3 values write properly to the CSV. other
 
Since you're relying on the default implementation of ToString on your Date variable, it's possible that it's creating a formatted date that Oracle doesn't like. For example: it might be using dd/mm/yy and Oracle can't tell the dateparts apart.

Look up in your Oracle docs to see what formats it supports, then use a custom date formatting string in a call to ToString to ensure it can be read:
Code:
FileDate3.ToString("yyyy-MM-dd")
Note that custom datetime format strings are case-sensitive. If you use a lower-case "mm", you get minutes, not months.

Chip H.

____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Just a quick hint about your WriteLine construction:

Try to use the built-in construction with parameters:

In stead of

myfile.WriteLine(FileDate3 & "," & campaignValue & "," & kwsiteValue & "," & kwsitetypeValue & "," & campstatusValue & "," & impsValue & "," & clicksValue & "," & cost & "," & pos)

write

myfile.WriteLine("{0},{1},{2},{3},{4},...",FileDate3.Tostring("yyyy-MM-dd"),campaignValue,...)

It will be easier later to see what you are writing and you can easily insert or remove items later, without accidentily leaving 2 commas in a row or something similar.

Just a tip!

Regards, Ruffnekk
---
Basic Instructions Before Leaving Earth (B.I.B.L.E.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top