RE: SqlCeEngine.CreateDataBase() - LCID - Datepart format problem

From: Amy Yuan [MS] (amyy_at_online.microsoft.com)
Date: 08/03/04


Date: Tue, 03 Aug 2004 20:27:35 GMT

Michel,

Background info on why insert in your format doesn't work: when you insert
datetime as string, SQL CE does an implicit convert from string to
datetime. When it does the convert, it doesn't consider locale and uses
default or specified locale instead. If your datetime format doesn't match
the default style, then it'd fail.

One of the following solutions would help:
1. insert as datetime type SqlDateTime
2. try the different datetime format to find the default format - different
datetime formats with their style IDs are listed in CONVERT function in SQL
CE BOL
3. use convert function to explictly convert your string to datetime using
appropriate style ID

Thanks,
Amy

--------------------
| X-Tomcat-ID: 541758672
| References: <b04f9dd.0407281348.17c822d8@posting.google.com>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: amyy@online.microsoft.com (Amy Yuan [MS])
| Organization: Microsoft
| Date: Tue, 03 Aug 2004 19:11:23 GMT
| Subject: RE: SqlCeEngine.CreateDataBase() - LCID - Datepart format problem
| X-Tomcat-NG: microsoft.public.sqlserver.ce
| Message-ID: <cdFRs2YeEHA.2788@cpmsftngxa10.phx.gbl>
| Newsgroups: microsoft.public.sqlserver.ce
| Lines: 55
| Path: cpmsftngxa10.phx.gbl
| Xref: cpmsftngxa10.phx.gbl microsoft.public.sqlserver.ce:13132
| NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122
|
| Hi Michel,
|
| You can explicitly convert datetime data to your specified format by
using
| convert function: insert into foo values( convert (datetime,
'12/31/2004',
| 101)); For more info on CONVERT function, you can go to SQL CE BOL.
|
| Thanks,
| Amy
|
| --------------------
| | From: michelmk@hotmail.com (Michel)
| | Newsgroups: microsoft.public.sqlserver.ce
| | Subject: SqlCeEngine.CreateDataBase() - LCID - Datepart format problem
| | Date: 28 Jul 2004 14:48:13 -0700
| | Organization: http://groups.google.com
| | Lines: 28
| | Message-ID: <b04f9dd.0407281348.17c822d8@posting.google.com>
| | NNTP-Posting-Host: 200.157.150.4
| | Content-Type: text/plain; charset=ISO-8859-1
| | Content-Transfer-Encoding: 8bit
| | X-Trace: posting.google.com 1091051294 17026 127.0.0.1 (28 Jul 2004
| 21:48:14 GMT)
| | X-Complaints-To: groups-abuse@google.com
| | NNTP-Posting-Date: Wed, 28 Jul 2004 21:48:14 +0000 (UTC)
| | Path:
|
cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!news-out.cwi
|
x.com!newsfeed.cwix.com!nntp1.roc.gblx.net!nntp.gblx.net!nntp.gblx.net!news-
|
out.visi.com!news-out.octanews.net!petbe.visi.com!news.maxwell.syr.edu!postn
| ews2.google.com!not-for-mail
| | Xref: cpmsftngxa10.phx.gbl microsoft.public.sqlserver.ce:13082
| | X-Tomcat-NG: microsoft.public.sqlserver.ce
| |
| | Hi,
| |
| | I´m having a problem on creating a new sql server ce database with the
| | method SqlCeEngine.CreateDataBase() from .NET CF.
| |
| | I´m setting a locale identifier in the connection string (1046) to
| | create the database, here is the source code:
| |
| | -------
| | System.Data.SqlServerCe.SqlCeEngine eng = new
| | System.Data.SqlServerCe.SqlCeEngine(@"data source=\My
| | documents\test.sdf; Locale Identifier=1046");
| |
| | eng.CreateDatabase();
| | -------
| |
| | The data base is created, but when i try to insert a datetime field
| | with the format 'dd/MM/yyyy', wich is the date format for my locale
| | settings, i got an error of incorrect datepart from sqlserverce.
| |
| | My region settings are ok.
| |
| | Does anyone knows what´s wrong?
| | Is there another way to create a new database dynamically, instead of
| | using SqlCeEngine in .net CF ?
| |
| | Thanks,
| | Michel.
| |
|
|



Relevant Pages

  • Re: dateTime Manupulations
    ... Notice the quoted string, a specific format for a date & time. ... will need to convert that string into a DateTime. ... > datetime conversion between strings, however it was a datetime conversion ...
    (microsoft.public.dotnet.languages.vb)
  • Re: GetDate(): Bug? Feature? Anomaly?
    ... If you use a DATETIME value in a function that only accepts string ... to the format used to display dates - QA's default for displaying DATETIME ... SQL Server MVP ...
    (microsoft.public.sqlserver.programming)
  • Re: Axis <-> .Net xsd:date interoperability problem
    ... .NET can de-serialize from alternative string representations of the date, ... but you need to tell it the format to expect. ... DateTime to be set. ... serialization of all DateTime's. ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: Dates
    ... The SQL query is a string, so the date in it is a part of the string, not a separate DateTime value. ... Frederik Vanderhaeghe wrote: ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Failed to convert parameter value from a String to a DateTime
    ... perhaps the error occurs because SQL Server defaults to nvarchar when a parameter is NULL. ... I would try to declare the parameter as DateTime before to assign it the DBNull.Value. ... value may be a valid date such as '01/01/2007' or a null string. ...
    (microsoft.public.dotnet.framework.adonet)

Loading