Re: Convertin dbnull to string
- From: "Elton Wang" <anonymous@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 13 Apr 2005 18:43:17 -0700
I think what you should do is to assign dbnull value to
row item when date value is empty. It's like:
If txtDtDeleted.Text.Trim.Equals("") Then
dr.Item("DateDeleted") = DBNull.Value
Else
dr.Item("DateDeleted") = txtDtDeleted.Text
EndIf
HTH
Elton Wang
elton_wang@xxxxxxxxxxx
>-----Original Message-----
>I am sorry, here is my code:
>
>dr = DS.Tables("UserAccount").NewRow
> dr.Item("UserName") = txtUsrName.Text
> dr.Item("EmailAddress") = txtEmailID.Text
> dr.Item("Name") = txtDscript.Text
> dr.Item("Directory") = txtDefaultDir.Text
> dr.Item("Account") = txtAccount.Text
> dr.Item("UIC") = txtUIC.Text
> dr.Item("ChargeBack") = txtChargeBack.Text
> dr.Item("DateCreated") = txtDtCreated.Text
>
> dr.Item("DateDeleted") = txtDtDeleted.Text ---
Here is where I get
>the error
>
>Additional information: System.FormatException: String
was not recognized as
>a valid DateTime.
> at System.DateTimeParse.Parse(String s,
DateTimeFormatInfo dtfi,
>DateTimeStyles styles)
> at System.DateTime.Parse(String s, IFormatProvider
provider,
>DateTimeStyles styles)
> at System.DateTime.Parse(String s, IFormatProvider
provider)
> at System.Convert.ToDateTime(String value,
IFormatProvider provider)
> at System.String.System.IConvertible.ToDateTime
(IFormatProvider provider)
> at System.Convert.ToDateTime(Object value)
> at System.Data.Common.DateTimeStorage.Set(Int32
record, Object value)
> at System.Data.DataColumn.set_Item(Int32 record,
Object value)Couldn't
>store <> in DateDeleted Column. Expected type is
DateTime.
>
>
>How would I be able to convert the dbnull to a string?
>
>"Val Mazur (MVP)" wrote:
>
>> Hi,
>>
>> DbNull is a special value and not an empty string. In a
case of DateTime
>> datatype you cannot save empty string into this field,
because it is not a
>> character data type. You have to store Null or valid
date. Why do you need
>> to store an empty string? It is actually a great
advantage to use Nulls
>> instead of empty strings, because you know for sure
that field does not hold
>> a value in this case
>> --
>> Val Mazur
>> Microsoft MVP
>>
>> http://xport.mvps.org
>>
>>
>>
>> "40forty" <40forty@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message
>> news:DC3D8AB8-946E-4FEB-AFEE-
A0138CEF9619@xxxxxxxxxxxxxxxx
>> > Hello,
>> >
>> > I am trying to insert a new datarow. Everything
works fine except for
>> > three
>> > columns that have datetime data types. I keep
getting this error message
>> > "System.Data.DataColumn.set_Item(Int32 record, Object
value)Couldn't store
>> > <>
>> > in 'columnname' Column. Expected type is DateTime."
>> >
>> > Is there any way of converting a dbnull to string
using vb.net?
>>
>>
>>
>.
>
.
- Follow-Ups:
- Re: Convertin dbnull to string
- From: 40forty
- Re: Convertin dbnull to string
- References:
- Convertin dbnull to string
- From: 40forty
- Re: Convertin dbnull to string
- From: Val Mazur \(MVP\)
- Re: Convertin dbnull to string
- From: 40forty
- Convertin dbnull to string
- Prev by Date: template fill for Datagrid
- Next by Date: Re: SQLHelper.ExecuteReader - Connection Close
- Previous by thread: Re: Convertin dbnull to string
- Next by thread: Re: Convertin dbnull to string
- Index(es):
Relevant Pages
|