[Mono-bugs] [Bug 71173][Nor] New - System.Data.Odbc -- ExecuteScalar( ) returns System.String where System.Single is expected

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Tue, 11 Jan 2005 12:14:42 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by appasamy@rediffmail.com.

http://bugzilla.ximian.com/show_bug.cgi?id=71173

--- shadow/71173	2005-01-11 12:14:42.000000000 -0500
+++ shadow/71173.tmp.17508	2005-01-11 12:14:42.000000000 -0500
@@ -0,0 +1,87 @@
+Bug#: 71173
+Product: Mono: Class Libraries
+Version: 1.1
+OS: Red Hat 9.0
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: Sys.Data
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: appasamy@rediffmail.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: System.Data.Odbc -- ExecuteScalar( ) returns System.String where System.Single is expected
+
+Description of Problem:
+  
+        In programs using System.Data.Odbc , ExecuteScalar() returns 
+System.String type of value for a Sql query where System.Single is 
+expected. Queries using aggregate functions sum(),avg() are the two where 
+this problem occurs. Remaining count(),max()and min() all returns as they 
+expected.
+
+Steps to reproduce the problem:
+
+1. Create a table in MySQL using following description
+
++--------+-------------+------+-----+---------+-------+
+| Field  | Type        | Null | Key | Default | Extra |
++--------+-------------+------+-----+---------+-------+
+| E_Name | varchar(20) | YES  |     | NULL    |       |
+| age    | int(11)     | YES  |     | NULL    |       |
+| salary | float       | YES  |     | NULL    |       |
++--------+-------------+------+-----+---------+-------+
+
+2.Type the following program and run
+ 
+ using System;
+ using System.Data;
+ using System.Data.Odbc; 
+ public class Test 
+ {
+    public static void Main(string[] args)
+    {
+    string connectionString = 
+          "DSN=Default;"+ 
+          "SERVER=localhost;" +
+           "Database= Employee;"+
+           "UID=somebody;"+
+            "OPTION=3;" ;
+         
+       IDbConnection dbcon;
+       dbcon= new OdbcConnection(connectionString);
+       dbcon.Open();
+       IDbCommand dbcmd = dbcon.CreateCommand();
+       string sql = "SELECT sum(salary) FROM emp_data";
+       dbcmd.CommandText = sql;
+       Object sal=dbcmd.ExecuteScalar();
+       Console.WriteLine(sal.GetType());
+       float newsal=(float)sal;
+       Console.WriteLine(newsal); 
+       dbcmd.Dispose();
+       dbcmd = null;
+       dbcon.Close();
+       dbcon = null;
+    }
+ }
+ 
+
+Actual Results:
+           System.String
+           Unhandled Exception: System.InvalidCastException: Cannot cast 
+from source type to destination typ e.in <0x000d6> Test:Main (string[])
+
+
+Expected Results:
+          System.Single 
+          12000.50
+
+
+
+Additional Information:
+             The avg(salary) also returns System.String. So I am unable  
+to do calculations with the return value .