Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

A Client refers to the person who incurs the development cost.

A Customer refers to the person that pays to use the product.

------

My software never has bugs. It just develops random features. (Mosabama vbforums.com)

Posted

Are you saying it's treating a 0 as a number instead of a string? Perhaps if the CSV data had quotes around it: '000073' instead of 000073 may work to tell whatever is determining the column type that it's a string, not a number data type?

 

Just a thought.

Posted
Are you saying it's treating a 0 as a number instead of a string? Perhaps if the CSV data had quotes around it: '000073' instead of 000073 may work to tell whatever is determining the column type that it's a string, not a number data type?

 

Just a thought.

 

Thats how I have got around the problem at the moment, but it does not seem to be the most appropriate solution. What I was doing before was to read the .csv file using a reader, and then loop though each line looking for ",". But this solution is not suitable for the approach that I am taking.

 

Mike55.

A Client refers to the person who incurs the development cost.

A Customer refers to the person that pays to use the product.

------

My software never has bugs. It just develops random features. (Mosabama vbforums.com)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...