I am attempting to parse data from a flat file into a DataSet table. Some of
the columns are amount fields (decimal) or dateTime.

The flat file can contain spaces or low-values in cases where there is no
valide money or date. These should be treated as "null".

How do I initialize these columsn to null in this case. (I'm thinking of
something like DBNull)

Re: How do I write a "null" into dateTime and decimal columns? by Jon

Jon
Thu May 13 12:13:11 CDT 2004

Tom <nfr@nospam.com> wrote:
> I am attempting to parse data from a flat file into a DataSet table. Some of
> the columns are amount fields (decimal) or dateTime.
>
> The flat file can contain spaces or low-values in cases where there is no
> valide money or date. These should be treated as "null".
>
> How do I initialize these columsn to null in this case. (I'm thinking of
> something like DBNull)

Well, what happens when you just put DBNull.Value in the datatable?

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Re: How do I write a "null" into dateTime and decimal columns? by Tom

Tom
Thu May 13 12:26:04 CDT 2004


"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.1b0dbd003812032498a8d6@msnews.microsoft.com...
> Well, what happens when you just put DBNull.Value in the datatable?

It generates compile errors.

Here is a short example of what I am attempting (twsContractHdr is a table
in a strongly typed DataSet)

public void ConvertFTPtoDataset()
{
[...]

TwsDS.twsContractHdrRow h =
twsds.twsContractHdr.NewtwsContractHdrRow();

h.RedemAmt = DBNull.Value;
h.RedemThru = DBNull.Value;

[...]
}

Compile errors are:
Cannot implicity convert type 'System.DBNull' to 'decimal'
Cannot implicity convert type 'System.DBNull' to 'System.DateTime'



Re: How do I write a "null" into dateTime and decimal columns? by Jon

Jon
Thu May 13 12:38:38 CDT 2004

Tom <nfr@nospam.com> wrote:
> > Well, what happens when you just put DBNull.Value in the datatable?
>
> It generates compile errors.
>
> Here is a short example of what I am attempting (twsContractHdr is a table
> in a strongly typed DataSet)

Ah - I didn't know you were using a strongly typed dataset. That
changes things, I'm afraid - and I don't have any experience with them
myself (mainly having worked on the Compact Framework which doesn't
have them).

Are there any other properties which indicate whether or not the value
is null?

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Re: How do I write a "null" into dateTime and decimal columns? by David

David
Thu May 13 13:09:06 CDT 2004


"Tom" <nfr@nospam.com> wrote in message
news:%23yijo9QOEHA.3752@TK2MSFTNGP12.phx.gbl...
>
> "Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
> news:MPG.1b0dbd003812032498a8d6@msnews.microsoft.com...
> > Well, what happens when you just put DBNull.Value in the datatable?
>
> It generates compile errors.
>
> Here is a short example of what I am attempting (twsContractHdr is a table
> in a strongly typed DataSet)
>
> public void ConvertFTPtoDataset()
> {
> [...]
>
> TwsDS.twsContractHdrRow h =
> twsds.twsContractHdr.NewtwsContractHdrRow();
>
> h.RedemAmt = DBNull.Value;
> h.RedemThru = DBNull.Value;
>

You work around this by setting

h[TwsDS.twsds.twsContractHdr.RedemAmtColumn] = DBNull.Value;

Or by just not setting it at all.

David



Re: How do I write a "null" into dateTime and decimal columns? by anonymous

anonymous
Fri May 14 11:21:02 CDT 2004

Have you tried this

public void ConvertFTPtoDataset(

[...

TwsDS.twsContractHdrRow h
twsds.twsContractHdr.NewtwsContractHdrRow()

h.SetRedemAmtNull()
h.SetRedemThruNull()

[...


----- Tom wrote: ----


"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in messag
news:MPG.1b0dbd003812032498a8d6@msnews.microsoft.com..
> Well, what happens when you just put DBNull.Value in the datatable

It generates compile errors

Here is a short example of what I am attempting (twsContractHdr is a tabl
in a strongly typed DataSet

public void ConvertFTPtoDataset(

[...

TwsDS.twsContractHdrRow h
twsds.twsContractHdr.NewtwsContractHdrRow()

h.RedemAmt = DBNull.Value
h.RedemThru = DBNull.Value

[...


Compile errors are
Cannot implicity convert type 'System.DBNull' to 'decimal
Cannot implicity convert type 'System.DBNull' to 'System.DateTime




Re: How do I write a &quot;null&quot; into dateTime and decimal columns? by SqlJunkies

SqlJunkies
Tue May 18 14:15:02 CDT 2004

This issue slowed me down for days. This should work:

1. Go to the XSD for your typed dataset.
2. Select the field in the dataset that needs to accept null values.
3. If you're using VS.NET change "nillable" from "Default" to "True" in the Properties window. If you're working directly in the XML schema, add a 'nillable="true"' attribute to the field element.
4. Save the DataSet and rebuild the project.
5. Go to your client code. You should have a new method on your DataRow:
myDataRow.Set<fieldname>Null();


Hope this helps

---
Posted using Wimdows.net NntpNews Component -

Post Made from http://www.SqlJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.