Re: Inserting date datatypes via ado.net

From: M. Zeeshan Mustafa (zeeshan_at_no-spm.please.zeeshan.net)
Date: 07/02/04


Date: Fri, 2 Jul 2004 10:16:52 +0500

AFAIK when inserting in a datetime column, when you put
'#1/1/2004#' -- returns: syntax error covnerting datetime from
character string.
'7/1/2004' (or any combination format) -- will work fine.

and the error you're having is coming from SQL Server.

Remember a date is a DATE, and it does not have any format.
When a date is represented in string, it has be in a format. A
format could be mm/dd/yyyy or any else format.

Check this:
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemdatasqlclientsqlparameterclassvaluetopic.asp

<quote>
If the application specifies the database type, the bound value is converted
to that type when the provider sends the data to the server. The provider
attempts to convert any type of value if it supports the IConvertible
interface. Conversion errors may result if the specified type is not
compatible with the value.

Both the SqlDbType and DbType properties can be inferred by setting the
Value.
</quote>

So we know that date does not have a formatted and from
above quote we learn that SqlParameter() can/will convert frameworks
Date object to its equivalent type of Sql.

Before adding parameter confirm that thedate (TextBox) contains
a valid date (can be in any machien understandable format), by using
IsDate() method.

-- 
Hope this helps,
Zeeshan Mustafa, MCSD
"J. Muenchbourg" <anonymous@dex.com> wrote in message
news:OJSpwH5XEHA.2408@tk2msftngp13.phx.gbl...
>
>
> I get the same exact "Syntax error converting datetime from character
> string" with >
> cmd.Parameters.Add(New SQLParameter("@thedate",
> Convert.ToDateTime(thedate.text)))
>
> The date format I am using for 'thedate' is mm/dd/yyyy . Do I have to
> explicitly use a format function to enter it as this?
>
> *** Sent via Devdex http://www.devdex.com ***
> Don't just participate in USENET...get rewarded for it!


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: 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: convert a date to a string?
    ... converting it to a CHARACTER string. ... Also, don't convert it back to a datetime, or put it in a datetime variable, ... or you'll lose the format. ... >>> Declare @m int ...
    (microsoft.public.sqlserver.programming)
  • Re: Search an Outlook appointment
    ... Then I can make my search string using the strDate. ... And my problem is to convert datetime to a string: ... How can I get the right datetime format of the user for making the search? ... I need to search for Outlook appointements from date to date. ...
    (microsoft.public.win32.programmer.messaging)
  • RE: SqlCeEngine.CreateDataBase() - LCID - Datepart format problem
    ... Background info on why insert in your format doesn't work: ... datetime as string, SQL CE does an implicit convert from string to ... datetime formats with their style IDs are listed in CONVERT function in SQL ...
    (microsoft.public.sqlserver.ce)