[Mono-bugs] [Bug 71261][Wis] New - System.Data.Odbc - GetOrdinal( ) not returning value

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Fri, 14 Jan 2005 06:08:32 -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=71261

--- shadow/71261	2005-01-14 06:08:32.000000000 -0500
+++ shadow/71261.tmp.19442	2005-01-14 06:08:32.000000000 -0500
@@ -0,0 +1,102 @@
+Bug#: 71261
+Product: Mono: Class Libraries
+Version: 1.1
+OS: Red Hat 9.0
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: Sys.Data
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: appasamy@rediffmail.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: System.Data.Odbc - GetOrdinal( ) not returning value 
+
+Description of Problem:
+
+In programs using System.Data.Odbc , GetOrdinal()throws error without
+giving the ordinal number of the column even when  the column name is
+given to it correctly.
+
+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 
+     {
+
+         --------
+         --------
+       dbcon= new OdbcConnection(connectionString);
+       dbcon.Open();
+       IDbCommand dbcmd = dbcon.CreateCommand();
+       string sql = "SELECT * FROM emp_data";
+       dbcmd.CommandText = sql;
+       IDataReader reader = dbcmd.ExecuteReader();
+       int ord_num= reader.GetOrdinal("age"); 
+       Console.WriteLine("ordinal Number  : "+ ord_num);
+       while(reader.Read())
+       {
+          Console.WriteLine("Age : "+ reader.GetValue(ord_num));
+       }
+       reader.Close();
+       reader = null;
+       dbcmd.Dispose();
+       dbcmd = null;
+        --------
+        --------
+
+    }
+
+Actual Results:
+
+ Unhandled Exception: System.IndexOutOfRangeException: Array index is out 
+of rang e.
+in <0x0002f> System.Data.Odbc.OdbcDataReader:GetOrdinal (string)
+in <0x000c4> Test:Main (string[])
+
+
+Expected Results:
+
+ordinal Number  : 1
+Age:22
+Age:23
+Age:24
+Age:22
+     
+
+
+
+
+Additional Information:
+
+            GetOrdinal() on the otherhand gives the correct value
+if I call reader.Read() before it as follws
+
+
+reader.Read();
+int ord_num= reader.GetOrdinal("age"); 
+
+
+But the record is moved by one  pointer which is not needed.Also to call 
+GetOrdinal()there is no need to call reader.Read() before it.When I use 
+ByteFX.Data.SqlClient it gives the result as expected.