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 [EMAIL PROTECTED] http://bugzilla.ximian.com/show_bug.cgi?id=81345 --- shadow/81345 2007-04-10 09:41:05.000000000 -0400 +++ shadow/81345.tmp.5016 2007-04-10 09:41:06.000000000 -0400 @@ -0,0 +1,91 @@ +Bug#: 81345 +Product: Mono: Class Libraries +Version: 1.2 +OS: GNU/Linux [Other] +OS Details: Slackware Linux v11.0 +Status: NEW +Resolution: +Severity: +Priority: Major +Component: Sys.Data.OleDb +AssignedTo: [EMAIL PROTECTED] +ReportedBy: [EMAIL PROTECTED] +QAContact: [EMAIL PROTECTED] +TargetMilestone: --- +URL: +Cc: +Summary: OdbcDataReader fails to convert data types to string with .GetString() method + +Important Note: +This bug report is for the ODBC class (which doesn't exist here) and not +for the OleDB, but the problem may also be relevant. + +Description of Problem: +When I call the method OdbcDataReader::GetString() on a field that is not +natively a string (ex: Int32, DateTime), this method will fail. It will +throw an exception that the source and destination type are incompatible. + +Steps to reproduce the problem: +1. Create a database table with various types: char, int, DateTime +2. Use an OdbcDataReader to read in each row +3. For each field in the OdbcDataReader object, call the GetString(int i) +method. +4. It will work for string based fields, but it will throw an exception for +everything else. + +Actual Results: +All fields should automatically be converted to the string without throwing +an exception. + +Expected Results: +Schema: Char Int DateTime +Data: Test1 0 01/01/2007 00:00 +Result: "Test1" "0" "01/01/2007 00:00" +Actual: "Test1" Exception Exception + +How often does this happen? +Always. + +Workaround: +Temporarily, developers can check the data type of the field and assign it +to the respected object, from which you can later convert to string via the +ToString() method; however this is extra labour that is not necessary. + +Additional Information: +Language: C#, ASP.NET +Runtime: Apache v2.2.4 (/w mod_mono) with XSP v1.2.3 and Mono v1.2.3.1 +Database: MySQL v4.1.22 +ODBC: MySQL Connector ODBC v3.51.14 x86 +Driver: unixODBC v2.2.12 + +Example Code: +public void query (string connectString, string SQLCommand) +{ + // Obtain data from the database using an OdbcDataReader + // Open a connection to the database + OdbcConnection connection = new OdbcConnection(connectString); + connection.Open(); + + // Obtain a reader with the given SQL command + OdbcConnection command = new OdbcCommand(SQLCommand, connection); + OdbcDataReader reader = command.ExecuteReader(); + + // Fetch the first row and display the fields + if ( reader.Read() ) + { + for (int i = 0; i < reader.FieldCount; i++) + { + try + { + // This should work for all fields + Response.Write( reader.GetString(i) + "<br>"); + } + catch (Exception e) + { + // Called when the field data type is not string based + throw e; + } + } + reader.Close(); + } +} _______________________________________________ mono-bugs maillist - [email protected] http://lists.ximian.com/mailman/listinfo/mono-bugs
