MySQL Forums :: MySQL for Visual Studio :: Read using ExecuteScalar

Advanced Search

Re: Read using ExecuteScalar
Posted by: Luis Penunuri ()
Date: March 08, 2016 05:28PM

Hi Hunnar,

Thank you for using MySql as your database provider.

How are you storing the result of the ExecuteScalar command ?

Consider the following scenario:
1.- A database called "test", with a table called "people", having a column called "Salary", which is of type "VARCHAR(45)", and storing the values: "9.25", "28.5", ...

2.- Having the following code:
Dim conn As MySql.Data.MySqlClient.MySqlConnection
Dim cmd As MySql.Data.MySqlClient.MySqlCommand
Dim res As Integer
conn = New MySql.Data.MySqlClient.MySqlConnection("Server=my_server;Database=test;Uid=user_id;Pwd=user_password;")
cmd = New MySql.Data.MySqlClient.MySqlCommand("SELECT Salary FROM people WHERE Age=20")
cmd.Connection = conn
res = cmd.ExecuteScalar()

The result you will see in the output is 9, because the datatype holding the ExecuteScalar command is Integer. If you change it to string or decimal, you should be able to see the correct value "9.25".

Please let me know if this scenario describes what you are currently getting.

Thank you, and have a good one !

Options: ReplyQuote

Subject Views Written By Posted
Read using ExecuteScalar 860 Gunnar Wallier 03/01/2016 08:23AM
Re: Read using ExecuteScalar 413 Luis Penunuri 03/08/2016 05:28PM
Re: Read using ExecuteScalar 424 Gunnar Wallier 03/09/2016 12:03AM
Re: Read using ExecuteScalar 398 Luis Penunuri 03/09/2016 10:54AM
Re: Read using ExecuteScalar 377 Gunnar Wallier 03/10/2016 12:43AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.