473,385 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to read Hyphenated Values from CSV File?

Hi,

I'm using the OleDB namespace to open a CSV File. I can read the file
sucessfully except for hyphenated values. My CSV File contains phone numbers
and sometimes these come separated with hyphens (ie: 555-123-4567). These
fields come as empty using the OleDB namespace and as dbNull when using the
ODBC namespace. Is there a way to prevent this from happening?

Thanks in advance,
Dec 7 '05 #1
4 2579
On Wed, 7 Dec 2005 10:38:02 -0800, "Antonio Tirado"
<An***********@discussions.microsoft.com> wrote:
Hi,

I'm using the OleDB namespace to open a CSV File. I can read the file
sucessfully except for hyphenated values. My CSV File contains phone numbers
and sometimes these come separated with hyphens (ie: 555-123-4567). These
fields come as empty using the OleDB namespace and as dbNull when using the
ODBC namespace. Is there a way to prevent this from happening?

Thanks in advance,


CSV should not have any problem with hyphens. What is your phone
number field expecting? If it is expecting digits only then hyphens
will cause a problem.

Try breaking the problem into two steps:
1 Load the phone number field into a simple text field and check
that it arrives correctly.
2 Once you have the text field part working then put the text into
the right format for your phone number field.

You can recombine the two steps into one once you are happy you
understand what is going on.

rossum

The ultimate truth is that there is no ultimate truth
Dec 7 '05 #2
Hi,

I used a DataReader to parse the CSV File. And for my Phone number I'm
expecting a string because sometimes phone numbers can be hyphenated. I tried
using GetString but this fails for other fields. With GetValue the phone
number comes either empty or null. I don't understand how to use the function
GetValues(). Nothing I tried seems to work.

Just in case, this is the code I'm using to get the values from the CSV File:

System.Data.OleDb.OleDbDataReader ParseCSVFile = CSVFile.ExecuteReader();

while (ParseCSVFile.Read())
{
string[] Line = new string[ParseCSVFile.FieldCount];
for (int i = 0; i < ParseCSVFile.FieldCount; i++)
Line[i] = ParseCSVFile.GetValue(i).ToString();
(...)

Thanks in advance,
"rossum" wrote:
On Wed, 7 Dec 2005 10:38:02 -0800, "Antonio Tirado"
<An***********@discussions.microsoft.com> wrote:
Hi,

I'm using the OleDB namespace to open a CSV File. I can read the file
sucessfully except for hyphenated values. My CSV File contains phone numbers
and sometimes these come separated with hyphens (ie: 555-123-4567). These
fields come as empty using the OleDB namespace and as dbNull when using the
ODBC namespace. Is there a way to prevent this from happening?

Thanks in advance,


CSV should not have any problem with hyphens. What is your phone
number field expecting? If it is expecting digits only then hyphens
will cause a problem.

Try breaking the problem into two steps:
1 Load the phone number field into a simple text field and check
that it arrives correctly.
2 Once you have the text field part working then put the text into
the right format for your phone number field.

You can recombine the two steps into one once you are happy you
understand what is going on.

rossum

The ultimate truth is that there is no ultimate truth

Dec 8 '05 #3
On Thu, 8 Dec 2005 04:36:04 -0800, "Antonio Tirado"
<An***********@discussions.microsoft.com> wrote:
Hi,

I used a DataReader to parse the CSV File. And for my Phone number I'm
expecting a string because sometimes phone numbers can be hyphenated. I tried
using GetString but this fails for other fields. With GetValue the phone
number comes either empty or null. Then use GetString() for the phone number fields and GetValue for the
other fields.
I don't understand how to use the function
GetValues(). Nothing I tried seems to work.

Just in case, this is the code I'm using to get the values from the CSV File:
// Returns true if index refers to a phone number field,
// false otherwise.
private bool isPhoneNumberIndex(int index) { /***/ }
System.Data.OleDb.OleDbDataReader ParseCSVFile = CSVFile.ExecuteReader();

while (ParseCSVFile.Read())
{
string[] Line = new string[ParseCSVFile.FieldCount];
for (int i = 0; i < ParseCSVFile.FieldCount; i++) if (isPhoneNumberIndex(i) {
Line[i] = ParseCSVFile.GetString(i);

/*** Diagnostic code ***/
string message = "Field[" +
i.ToString() +
"] = " +
Line[i];
MessageBox.Show(message, "Phone Number");
/***********************/
}
else { Line[i] = ParseCSVFile.GetValue(i).ToString(); } // end if(...)
A minor point, in for-loops ++i is never slower and may be faster than
i++.

rossum

Thanks in advance,
"rossum" wrote:
On Wed, 7 Dec 2005 10:38:02 -0800, "Antonio Tirado"
<An***********@discussions.microsoft.com> wrote:
>Hi,
>
>I'm using the OleDB namespace to open a CSV File. I can read the file
>sucessfully except for hyphenated values. My CSV File contains phone numbers
>and sometimes these come separated with hyphens (ie: 555-123-4567). These
>fields come as empty using the OleDB namespace and as dbNull when using the
>ODBC namespace. Is there a way to prevent this from happening?
>
>Thanks in advance,


CSV should not have any problem with hyphens. What is your phone
number field expecting? If it is expecting digits only then hyphens
will cause a problem.

Try breaking the problem into two steps:
1 Load the phone number field into a simple text field and check
that it arrives correctly.
2 Once you have the text field part working then put the text into
the right format for your phone number field.

You can recombine the two steps into one once you are happy you
understand what is going on.

rossum

The ultimate truth is that there is no ultimate truth

The ultimate truth is that there is no ultimate truth
Dec 10 '05 #4
Hi, I managed to used the GetValues() function but the problem is still
happening. Thanks for the detail about ++i anyways.

Just to sum it up: WHen parsing hyphenated phone numbers from a CSV File
using the OleDB Space I'm getting DBNull values. Someone tried my exact code
in his own PC and it works perfectly. Could this be related to the file?

"rossum" wrote:
On Thu, 8 Dec 2005 04:36:04 -0800, "Antonio Tirado"
<An***********@discussions.microsoft.com> wrote:
Hi,

I used a DataReader to parse the CSV File. And for my Phone number I'm
expecting a string because sometimes phone numbers can be hyphenated. I tried
using GetString but this fails for other fields. With GetValue the phone
number comes either empty or null.

Then use GetString() for the phone number fields and GetValue for the
other fields.
I don't understand how to use the function
GetValues(). Nothing I tried seems to work.

Just in case, this is the code I'm using to get the values from the CSV File:

// Returns true if index refers to a phone number field,
// false otherwise.
private bool isPhoneNumberIndex(int index) { /***/ }
System.Data.OleDb.OleDbDataReader ParseCSVFile = CSVFile.ExecuteReader();

while (ParseCSVFile.Read())
{
string[] Line = new string[ParseCSVFile.FieldCount];
for (int i = 0; i < ParseCSVFile.FieldCount; i++)

if (isPhoneNumberIndex(i) {
Line[i] = ParseCSVFile.GetString(i);

/*** Diagnostic code ***/
string message = "Field[" +
i.ToString() +
"] = " +
Line[i];
MessageBox.Show(message, "Phone Number");
/***********************/
}
else {
Line[i] = ParseCSVFile.GetValue(i).ToString();

} // end if
(...)


A minor point, in for-loops ++i is never slower and may be faster than
i++.

rossum

Thanks in advance,
"rossum" wrote:
On Wed, 7 Dec 2005 10:38:02 -0800, "Antonio Tirado"
<An***********@discussions.microsoft.com> wrote:

>Hi,
>
>I'm using the OleDB namespace to open a CSV File. I can read the file
>sucessfully except for hyphenated values. My CSV File contains phone numbers
>and sometimes these come separated with hyphens (ie: 555-123-4567). These
>fields come as empty using the OleDB namespace and as dbNull when using the
>ODBC namespace. Is there a way to prevent this from happening?
>
>Thanks in advance,

CSV should not have any problem with hyphens. What is your phone
number field expecting? If it is expecting digits only then hyphens
will cause a problem.

Try breaking the problem into two steps:
1 Load the phone number field into a simple text field and check
that it arrives correctly.
2 Once you have the text field part working then put the text into
the right format for your phone number field.

You can recombine the two steps into one once you are happy you
understand what is going on.

rossum

The ultimate truth is that there is no ultimate truth

The ultimate truth is that there is no ultimate truth

Dec 10 '05 #5

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

Similar topics

6
by: Ruben | last post by:
Hello. I am trying to read a small text file using the readline statement. I can only read the first 2 records from the file. It stops at the blank lines or at lines with only spaces. I have a...
5
by: Nils Wogatzky | last post by:
Hi, I´ve got a problem with the iftream.read method. I´m reading out a binary file, but I receive wrong values if values are negative. m_File.read((char*)&help2,2); so, help2 is...
2
by: joerg pfeffer | last post by:
hello, I want to read the style.top of an image when I open the page with: document.getElementById("myimage").style.top But unfortunately the value has no properties.... Does this happen,...
14
by: Larry R Harrison Jr | last post by:
I have designed databases but have never come across any complications due to the ridiculous situation of a hyphenated last name. As a database designer (very junior level) I disdain anything...
3
by: Sobhan | last post by:
Hi all, I am writing a program in C in which I need to read a data file and export to the excel.The Data in the file in CSV format. Values in the .txt file are as follows: "a","b","c" 10,20,30...
23
by: comp.lang.tcl | last post by:
I have a TCL proc that needs to convert what might be a list into a string to read consider this: ]; # OUTPUTS Hello World which is fine for PHP ]; # OUTPUT {{-Hello}} World, which PHP...
7
by: Mary | last post by:
I have a student who has a hyphenated first name. If I concatenate the name like this: StudentName:( & ", " & ), it works as expected. If, however, I try to get the first name first by...
2
by: RyanS09 | last post by:
Hi- I have read many posts with specific applications of reading in text files into arrays, however I have not been able to successfully modify any for my application. I want to take a text file...
13
by: rohit | last post by:
Hi All, I am new to C language.I want to read integers from a text file and want to do some operation in the main program.To be more specific I need to multiply each of these integers with another...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.