Re: Convertin dbnull to string

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



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?
>>
>>
>>
>.
>
.



Relevant Pages

  • Re: Convertin dbnull to string
    ... DbNull is a special value and not an empty string. ... You have to store Null or valid date. ... > columns that have datetime data types. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: DateTime Picker
    ... The DateTimePicker has no concept of empty dates. ... datetime really) or it's NULL. ... You have to catch the state of the control in the Change event and update ... > Also be sure to set the MinDate and MaxDate properties. ...
    (microsoft.public.fox.programmer.exchange)
  • FormView checkbox two-way bind problem with null fields
    ... In the source these fields my be empty. ... Conversion from type 'DBNull' to type 'Boolean' is not valid. ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: Enter "Empty" if cell is blank within a variable range
    ... Dim Test As String ... My suggeste code will populate all empty cells columns A:B, ... I have checked the value of the cell with the following. ... The debugger displays an empty string value. ...
    (microsoft.public.excel.programming)
  • Re: Semi OT: To Null or not to Null
    ... And suppose that an empty string is a ... decision to put a value, even an empty or default one, in that field. ... > Load() ... > nulls, or checking on save to transform defaults to nulls. ...
    (microsoft.public.dotnet.languages.csharp)