I have a function that is one. Converts a Csv file to Datat. One of the columns I am converting is one area of the name in which there is a comma in them I.e. When converting "Do, John" function, it behaves like 2 different areas due to commas. I need a dateline to place this field, John in the database.
using a Do not SPTIT ()
function to read your CSV data. Not only the kind of mistake you have made, but it is slow you need a state machine based parser. It will be faster and it will be easy to handle the quote-attached text correctly.
I have an example here:
And there is also a highly respected CSV reader on CodePlex, you can use it:
You will use your code in this way:
Function DatableFront CSV (String in the form of binline filename) Datatale as Dim Table in the form of new DataTable dim colAdded Boolean = False 'For every record IList (string of) in CSV.FromFile (file name) for' # first or If the column headers are added then each token string is in the form of table.Columns.Add as then not colAdded (token) next token colAdded = true or else the DataRow = table.NewRow table add row to the dim row () I as integer = 0 to table.Columns.Count - 1 row (i) = record (i) Next table. Rows. Add (line) closing if the next record return table expiration function
If you are using .NET 3.5 or later, then I pull out the column build for each loop (Typed conclusion and using (1)
), but I have to make sure that it will also work with Net 2.0.
Comments
Post a Comment