this give me not the corrected sum(42), suppose to be 43,91
Gold_gr is a text field column which has numbers
Code:
Using conn As New SQLiteConnection(connection)
conn.Open()
Dim query As String = "SELECT SUM(Gold_gr) from users"
Using command As New SQLiteCommand(query, conn)
TextBox6.Text = Convert.ToString(command.ExecuteScalar())
End Using
Last edited by marsias; Nov 26th, 2024 at 11:31 AM.
Many ways exist to Babylon.
Only the shortest is the Best.
Text fields aren’t number fields. It looks like the sql is trying to convert the text to numbers, but because they aren’t valid decimal numbers (7.32 instead of 7,32) it isn’t interpreting it correctly.
Dim connectionString As String = "Your_Connection_String_Here"
Dim query As String = "SELECT SUM(ColumnName) FROM YourTableName"
Dim total As Decimal
Using connection As New SqlConnection(connectionString)
Dim command As New SqlCommand(query, connection)
connection.Open()
total = Convert.ToDecimal(command.ExecuteScalar())
End Using
Console.WriteLine("Total Sum: " & total)
Dim connectionString As String = "Your_Connection_String_Here"
Dim query As String = "SELECT SUM(ColumnName) FROM YourTableName"
Dim total As Decimal
Using connection As New SqlConnection(connectionString)
Dim command As New SqlCommand(query, connection)
connection.Open()
total = Convert.ToDecimal(command.ExecuteScalar())
End Using
Console.WriteLine("Total Sum: " & total)
command.ExecuteScalar() Returns an Object. Converting it to Decimal at that point wouldn’t fix the problem.
I’m still fairly sure it’s because of CultureInfo Decimal formatting…
Why? Do you have control of the database? If so, you should change that.
Failing that, you will need to actually convert the text to a number explicitly before summing, instead of expecting the system to do it for you and then complaining that it doesn't do it how you want. The first thing you should do is search for information on how to convert text to a number in SQLite.
Yepp.
Definitely the Column as Text issue instead of Datatype REAL
6 x 7.32 = 43.92
6 x 7 = 42
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad