Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have one csv file with column ip address,when i read csv data and bind in datatable,i will get only 1st dight.

if ip address like this 192.168.0.13
i will get 192.168 only,rest of thing skipped. Ip address column in csv file behave like decimal value.How to read full values.

VB
Dim fileneme As String = file1.FileName
Dim filepath As String = Server.MapPath(".") & "\" & Session("userid")
Dim strConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & filepath & ";Extended Properties=Text;"
                        Dim conn As New OleDbConnection(strConnString)

                        Try
                            conn.Open()
                            Dim cmd As New OleDbCommand("SELECT IPADDRESS FROM [" & fileneme & "]", conn)
                            Dim da As New OleDbDataAdapter()

                            da.SelectCommand = cmd

                            Dim dt As New DataTable()

                            da.Fill(dt)
                            da.Dispose()


What I have tried:

If i add double quotes in ip address value in csv,then i will get full value with double quotes in datatable,but cant add double quotes.
Pls reply asap


Regards

Aravind
Posted
Updated 30-Jun-16 21:58pm

That's because when Jet reads the CSV data, it assumes that 192.168 is a number, and processes it as such. It doesn't "know" it's an IP address, it just looks at the first character after the comma and says "Ah, numeric. This is a number, I'll parse it."
IP addresses in CSV files need to be delimited with double quotes to make them strings, unless you write (or modify an existing) CSV reader.
 
Share this answer
 
As OriginalGriff already said, without double quotes, the ip address format collide with decimal format, thus the problem.
There is a few solutions:
- the most standard solution is to embed the ip between double quotes. The reading program should take care of it since it conform to CSV standard.
- craft a custom routine to do the reading directly, file io ...
- Use a variant. I always use a variant of CSV format with tabs instead of commas and nothing around text fields. And I make a routine to do direct reading.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900