Retrieving data from a .CSV File...
VB
Thread Starter: mike55
Started:
Replies: 1

Ireland .NET Developer Alliance :: Forums » Technologies » VB » Retrieving data from a .CSV File...
« Previous Thread
   29 Dec 2005, 1:00
mike55 is not online. Last active: 29/12/2005 15:02:36 mike55

Top 10 Posts
Joined on 01-20-2005
Posts 42
Retrieving data from a .CSV File...
Hi all,

I am retrieving data from a .CSV file into a dataset, the problem that I am encountering is that the code/dataset seems to not pick up certain characters such as the 0 (Zero) characters at the start of the .CSV data field.

Here is the code that I am using, all/any suggestions welcomed...
                                      

'Retrieve the data from the .csv file.

Private Function RetrieveOrganisationUploadedMembership( ByRef dstCSVFile As DataSet, ByVal filePath As String , Optional ByRef errorMessage As String = Nothing ) As Boolean

RetrieveOrganisationUploadedMembership =

True

Dim cnnCSVConnection As OleDb.OleDbConnection

Try

Dim fileName As String

Dim path As String

Dim dcUpload(0) As DataColumn

fileName = System.IO.Path.GetFileName(filePath)

path = filePath.Replace(fileName,

Nothing )

cnnCSVConnection =

New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=Text;")

Dim cmdCSVCommand As OleDb.OleDbCommand = New OleDb.OleDbCommand("SELECT * FROM " & fileName, cnnCSVConnection)

Dim adpCSV As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(cmdCSVCommand)

' Open a connection to the .csv file and retrieve the data to a dataset.

cnnCSVConnection.Open()

adpCSV.Fill(dstCSVFile, "MemberData")

' Set the primary key.

dcUpload(0) = dstCSVFile.Tables(0).Columns("MobileNumb")

dstCSVFile.Tables(0).PrimaryKey = dcUpload

Return RetrieveOrganisationUploadedMembership

Catch ex As Exception

errorMessage = "Problem Encountered, " & ex.Message.ToString.TrimEnd

RetrieveOrganisationUploadedMembership =

False

Finally

' Close the database connection.

cnnCSVConnection.Close()

End Try

End Function

 

Mike55.

  
   06 Jan 2006, 6:57
magician is not online. Last active: 16/01/2006 10:39:44 magician

Top 25 Posts
Joined on 08-23-2005
Posts 4
Re: Retrieving data from a .CSV File...
Hi,
looks like OLEDB recognizes text field as numeric ... ie instead of "0" ... you have ?

standard bug -> use schema.ini file
format that field as text

[MyFile.csv]
ColNameHeader=TRUE
Format=CSVDelimited
CharacterSet=ANSI
Col1="First Name" TEXT
Col2="Last Name" TEXT
Col3="Email" TEXT
Col4="MOILENUMBER" TEXT


schema.ini file ahs 2 B in exact same folder as file U trying 2 open

 
    
  Page 1 of 1 (2 items)
Ireland .NET Developer Alliance :: Forums » Technologies » VB » Retrieving data from a .CSV File...

Powered by Community Server :: Forums