samedi 25 avril 2015

INSERTing data with symbols

How should I go about inserting data in a database if there are symbol characters in the data to be inserted.

Sample Data inside a CSV File:

351442,351442,clc bed, futton 48" w/ mattres,9999.7500

351851,748485102207,CNTRY GRMT,BANGUS SPNSH184GX48,52.0000

352077,4806513109997,GLUTASILK, LOTION BLUE 50ML,57.5000

The data should be ITEM_NO,BARCODE,DESCRIPTION,PRICE

I have problems inserting the above data because of the Double Quotes and the Comma` inside the description.

First my program will take the line on the CSV File:

FileReader = New StreamReader(StringFileName)

Each line, I will split the data:TempArraySplitString = TempReaderString.Split(",")

Then insert the data:

        SqlCommand.CommandText = "INSERT INTO Items(Sku, Upc, Description, Price) VALUES('" & TempArraySplitString(0) & "','" & TempArraySplitString(1) & "','" & TempArraySplitString(2) & "','" & TempArraySplitString(3) & "')"
        SqlCommand.ExecuteNonQuery()

Error return since some line have , on the string.

How do I correctly separate each of the data to correctly insert into the database?

Aucun commentaire:

Enregistrer un commentaire