Question

Locked

Problem inserting csv file content to MySQL Table Using Visual Studio 2008

By jeffreyalejo ·
I have a csv file with the following content:

1, 029

I can insert it into the MySQL Database but the entered data looks like this:

Col1 Col2
1 29

It removes the 0 in the second column.

And here's my connection string:

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\UnzipFiles\;Extended Properties='Text;HDR=No;FMT=Delimited'"

I'm inserting the value of the 2nd column of the csv file in a variable(string), then that variable is used in the insert statement to add the record. At that point, the value 029 is already changed to 29.

I tried opening the csv file with Excel and Notepad and here's the difference:

In excel, 029 is converted to 29 while in Notepad 029 is not changed. It seems like it looks at the value of the columns based on the excel format.

Any help is highly appreciated. Thanks in advance.

Regards,

Jeff

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

csv import would expect strings to be

by Tony Hopkinson In reply to Problem inserting csv fil ...

delimited
e.g.
1,"029"

because it isn't, it's doing best guess to be helpful.

if you had
0,XXX
1,029

it would be a string

1,029
2,XXX
might work or it might **** chunks with XXX is not a number, depending on how helpful it chooses to be.

You could do your own import routine. You could import to a specific table with col2 defined as a char type.

or you could delimit the string(s).

Back to Software Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums