Re: Insert date 1900-01-01
From: Greg Burns (greg_burns_at_DONT_SPAM_ME_hotmail.com)
Date: 10/06/04
- Next message: Ken Cox [Microsoft MVP]: "RE: I don't obtain to use Server.Mappath..."
- Previous message: Lucas Tam: "Re: Daily Graphs of activity"
- In reply to: Greg Burns: "Re: Insert date 1900-01-01"
- Next in thread: Arek: "Re: Insert date 1900-01-01"
- Reply: Arek: "Re: Insert date 1900-01-01"
- Messages sorted by: [ date ] [ thread ]
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!
>>>
>
>
- Next message: Ken Cox [Microsoft MVP]: "RE: I don't obtain to use Server.Mappath..."
- Previous message: Lucas Tam: "Re: Daily Graphs of activity"
- In reply to: Greg Burns: "Re: Insert date 1900-01-01"
- Next in thread: Arek: "Re: Insert date 1900-01-01"
- Reply: Arek: "Re: Insert date 1900-01-01"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|