[Mono-bugs] [Bug 70209][Maj] New - Date formatting on Tds70.cs

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Sat, 4 Dec 2004 07:57:34 -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 rpaterlini@hotmail.com.

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

--- shadow/70209	2004-12-04 07:57:34.000000000 -0500
+++ shadow/70209.tmp.31000	2004-12-04 07:57:34.000000000 -0500
@@ -0,0 +1,94 @@
+Bug#: 70209
+Product: Mono: Class Libraries
+Version: 1.0
+OS: 
+OS Details: Win2003
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Major
+Component: Sys.Data.SqlClient
+AssignedTo: rodrigo@novell.com                            
+ReportedBy: rpaterlini@hotmail.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Date formatting on Tds70.cs
+
+Description of Problem:
+Error when calling stored procedure in SQLServer 2000 with a datetime
+parameter and Regional and Language Option set to Italian I have an
+conversion error 
+
+Runtime: mono 1.0.4 on Windows2003
+
+Steps to reproduce the problem:
+1. Build this sample
+
+ using System;
+ using System.Data;
+ using System.Data.SqlClient;
+
+ public class Test
+ {
+    public static void Main(string[] args)
+    {
+       string connectionString = "Server=192.168.1.1;Database=pubs;User
+ID=sa;Password=.....;";
+       
+	   SqlConnection dbcon = new SqlConnection(connectionString);
+       dbcon.Open();
+		
+       SqlCommand dbcmd = dbcon.CreateCommand();
+       dbcmd.CommandText =
+           "SELECT fname, lname, hire_date " +
+           "FROM employee " + 
+		   "where hire_date > @DateMin " +
+		   "order by hire_date";
+	   dbcmd.Parameters.Add("@DateMin", SqlDbType.DateTime).Value 
+			= new DateTime( 1993, 8, 15 );
+		dbcmd.Prepare();
+
+       IDataReader reader = dbcmd.ExecuteReader();
+       while(reader.Read()) {
+            string FirstName = (string) reader["fname"];
+            string LastName = (string) reader["lname"];
+            DateTime HireDate = (DateTime) reader["hire_date"];
+            Console.WriteLine("Name: " +
+                 FirstName + " " + LastName + ", " + HireDate.ToString("d") );
+       }
+       // clean up
+       reader.Close();
+       dbcmd.Dispose();
+       dbcon.Close();
+    }
+ }
+
+with mcs sql.cs /r:System.Data.dll
+2. From the control panel, change Regional and Language Option and set to
+Italian
+3. run it (mono sql.exe)
+
+Actual Results:
+Unhandled Exception: System.Data.SqlClient.SqlException: Error converting
+data type varchar to datetime.
+
+Expected Results:
+A list of some record
+
+How often does this happen? 
+Every time i have Regional and Language Option and set to Italian.
+With Regional and Language Option and set to English(US) it work
+
+Additional Information:
+In /mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds70.cs, method
+FormatParameter you need to add a case to format datetime and smalldatetime.
+This seem to work:
+			case "smalldatetime":
+			case "datetime":
+				DateTime d = (DateTime)parameter.Value;
+				value = String.Format(
+System.Globalization.CultureInfo.InvariantCulture, "'{0:MM/dd/yyyy hh:mm:ss
+tt}'", d );
+				break;