0

I'm currently trying to read data from a text file and insert it into a sqlite database

visual is reading the data(a decimal number using the decimal period i.e 4.56) using a fileReader, when the data is readed directly its in string form and shows correctly i.e 4.56, but when trying to convert to a number it uses a decimal coma format i.e 4,56 wich will not be a big issue if i didnt have to send it to the database (4,56 in a select its 2 fields a 4 and a 56)

By looking in other posts i see the default is the decimal period ( i see people with the oposite problem Visual basic handle decimal comma) CurrentRow is a string Array containing the current line in the file, the position 11 contains 19.90

MessageBox.Show(10 / 3) outputs 3,33333
MessageBox.Show(CurrentRow(11)) outputs 19.90
MessageBox.Show(Val(CurrentRow(11))) outputs 19,9
MessageBox.Show(Decimal.Parse(CurrentRow(11))) 1990
MessageBox.Show(Decimal.Parse(Val(CurrentRow(11)))) 19,9
cg7
  • 189
  • 1
  • 15
  • If you pass `CultureInfo.InvariantCulture` into `Decimal.Parse`, that should parse it correctly... and if you pass it to the database via a parameter, *without* converting it back to a string, you shouldn't need to care about string formatting. – Jon Skeet Aug 30 '18 at 14:40
  • The comma only matters if it is text. The **number** `4.56` has neither a comma nor a decimal. The **text expression** of it does so that humans can understand it. The Database is not going to care about decimal or comma if you pass a number. It would appear that `CurrentRow()` is a string array? – Ňɏssa Pøngjǣrdenlarp Aug 30 '18 at 14:59
  • The database doesnt care, but when building the query, if i insert that text '19,90' sqlite shows an error cause it thinks its 2 parameters (since params are separated by coma) i just tried using .ToString.Replace(",", ".") after the val() and it works, still replacing doesnt seem right, and yes CurrentRow() is a string array containing the current line in the file – cg7 Aug 30 '18 at 15:10
  • @cg7.baselines: The solution is to use parameterized SQL instead of creating SQLs with string concatenation. I have marked your question as a duplicate of a question which explains how to do that. – Heinzi Aug 30 '18 at 15:14
  • Again, there is only a comma presented to SQLite because you are passing **text** rather than a **number**. Depending on what the source text file looks like, you might be able to import it *en masse* ususing OleDB and then Update SQLite with just 5 or 6 lines of code – Ňɏssa Pøngjǣrdenlarp Aug 30 '18 at 15:19
  • @Heinzi Thank you man, that post was just what i needed – cg7 Aug 30 '18 at 18:00

0 Answers0