Re: Insert date 1900-01-01

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Greg Burns (greg_burns_at_DONT_SPAM_ME_hotmail.com)
Date: 10/06/04


Date: Wed, 6 Oct 2004 13:02:51 -0400

should have been...
> sqlcomm1.Parameters.Add("@OutDate", SqlDbType.DateTime).Value =
> CDate(txtOutdate.Text)

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:OiFURX8qEHA.2604@TK2MSFTNGP10.phx.gbl...
>I am not a not an expert in C#, but shouldn't that be DBNull.Value?
>
> Regardless, it is a lot cleaner using parameters...
>
> Dim sqlcomm1 As New SqlCommand("INSERT INTO tblTasks (idTask, outdate)
> VALUES (@ID, @OutDate)", conn)
>
> sqlcomm1.Parameters.Add("@ID", SqlDbType.Int).Value = CInt(IDTask.text)
>
> If Not txtOutdate.Text = String.Empty Then
> sqlcomm1.Parameters.Add("@OutDate", SqlDbType.DateTime).Value =
> CDate(txtOutdate)
> Else
> sqlcomm1.Parameters.Add("@OutDate", SqlDbType.DateTime).Value =
> DBNull.Value
> End If
>
> sqlcomm1.ExecuteNonQuery()
>
> HTH,
> Greg
>
>
>
> "Psycho" <Psycho@discussions.microsoft.com> wrote in message
> news:BEFE4046-82DF-4415-9B87-3344314C5604@microsoft.com...
>> in c#
>> txtOutdate.Text == string.empty ? null : txtOutdate.Text
>>
>> i'm sorry i am not expert in visualbasic.
>>
>> but i suppose you can make an if
>> if txtOutdate.Text == string.empty then
>> str = null
>> else
>> str = txtOutdate.Text
>>
>> I think you should also transform your string in datetime format
>> recognized
>> by sql.
>>
>>
>> "Arek" wrote:
>>
>>> Hey,
>>> I am inserting values in the table:
>>>
>>> Dim sqlcomm1 As SqlCommand = New SqlCommand("INSERT INTO tblTasks
>>> (idTask, outdate) VALUES ('" & IDTask.text & "','" & txtOutdate.Text &
>>> "')", conn)
>>> sqlcomm1.ExecuteNonQuery()
>>>
>>> Query is working fine if there is value in the txtOutDate, but if user
>>> leaves the field txtOutdate empty, system insert date 1900-01-01. I want
>>> system to insert null.
>>>
>>> How can I achieve that?
>>>
>>> Regards
>>> Arek
>>>
>>>
>>>
>>>
>>> *** Sent via Developersdex http://www.developersdex.com ***
>>> Don't just participate in USENET...get rewarded for it!
>>>
>
>



Relevant Pages

  • Re: Windows Server 2003 Ent. x64 Edition - Full-text Tuning
    ... Yes - (regardless of the OS). ... I assume you would run OS - /PAE /3GB and SQL using AWE? ... During the load - I appear to be CPU bound on the DB. ... > there are multiple instances of SQL Server 2000 installed. ...
    (microsoft.public.sqlserver.fulltext)
  • Re: Compiling pl/sql in sqlplus with an @ char within the code?
    ... regardless it is quoted). ... sqlplus to alter the defaults (e.g. the define is usually the & char) ... SQL> set runscript} ... clearly you can reassign the default '&' for substitution variables to another character or disable substitution behaviour at all ...
    (comp.databases.oracle.server)
  • Re: Heres your trusted UN data
    ... Regardless of what side of the global warming debate you're ... on, fact is, we need to move to cleaner, renewable fuel sources, ...
    (rec.motorcycles)
  • Re: How to ignore the Year in a Date - Query
    ... Thank you - I am not familar with SQL so please forgive my lack of knowledge ... parameters to be number, rather than letting Access guess, and comes with ... DatePart("d", dateTimeField) ... months regardless of the year. ...
    (microsoft.public.access.queries)
  • Re: How to ignore the Year in a Date - Query
    ... I also looked at the SQL view and now I understand what you were ... "vanderghast" wrote: ... DatePart("d", dateTimeField) ... Also, I'm ultimately looking to pull based on month and day, regardless ...
    (microsoft.public.access.queries)