Re: Strange error while executing query



Hello!

How about using a variable and assign "today.date" value to that variable in c# and use this variable as a parameter in your query code?

--
Ekrem Önsoy




"rvangeldrop" <rvangeldrop@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:56D73326-6B9B-482A-9D76-55162DE6E1DB@xxxxxxxxxxxxxxxx
Hi,

I have an unexpected error while executing the query below

If I run it in Management Studio it will work fine, but if I run it using my
code in C# on the same machine it will fail with the following exception:
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999
11:59:59 PM

I use 'System.Data.SqlClient.SqlCommand' and execute the query using
'ExecuteNonQuery'.

It fails because it wants to insert getdate(). If I replace getdate() with
NULL it works. If I then run an extra update query using a parameter with the
correct date in it, this will work too. I do have systems however, that
accept the original query.

How can this be and how can make it work?

Query:
insert into accounthistory
(UserInfoUserName,AccountInfoStatus,AccountInfoActive,AccountInfoHasDigiNotarKey,AccountInfoDigiNotarKeyIsStored,AccountInfoUsedSize,AccountInfoMaxVersions,AccountTypeID,AccountInfoOwnerID,AccountInfoStartDate,AccountInfoDigiNotarKey,AccountInfoDigiNotarKeyHash,AccountInfoTrialUser,AccountInfoChangedBy,AccountInfoUserProfileTypeID)
select
UserInfoUserName,AccountInfoStatus,AccountInfoActive,AccountInfoHasDigiNotarKey,AccountInfoDigiNotarKeyIsStored,AccountInfoUsedSize,AccountInfoMaxVersions,AccountTypeID,AccountInfoOwnerID,getdate(),AccountInfoDigiNotarKey,AccountInfoDigiNotarKeyHash,AccountInfoTrialUser,AccountInfoChangedBy,AccountInfoUserProfileTypeID from AccountInfo with (READUNCOMMITTED) where userinfousername=@0

.



Relevant Pages

  • Re: Mailmerge, querystring and (un)logical SQL (Word 2003)
    ... I have retried on datavalue within SQL sentence and it worked out! ... Too many records retrieved if executing the query with OR operators. ... The only way around this is to try to reduce the length of the query code, ...
    (microsoft.public.word.mailmerge.fields)
  • Re: Last Login
    ... Getdate() ... so this query will fail. ...
    (microsoft.public.sqlserver.programming)
  • Re: Format change from Access to Word
    ... Can you post the SQL query code being used here? ... Are the underlying fields currency types, or more general floating point types, e.g. double? ... If the query code is using the format function to format the output, does it make any difference if you covert the original amount to a double in the query using cdblbefore applying formatting? ...
    (microsoft.public.word.mailmerge.fields)
  • Re: New to SQL - Help needed with simple query
    ... query code. ... built in Accdb query: ... Could you suggest how my "WHERE" code line will be using SQL query? ... field (set their nullable property to false (don't allow for null value) and ...
    (microsoft.public.access.adp.sqlserver)
  • Re: Pull Field name from a form
    ... not subject to indirection. ... You can generate the SQL for the query in code, and place the name of the ... column desired into the query code. ... I'm using the following SQL to drive an Access Chart: ...
    (microsoft.public.access.queries)

Loading