Question DataColumn NullValue

JaedenRuiner

Well-known member
Joined
Aug 13, 2007
Messages
340
Programming Experience
10+
Well,

I was working to set up my import, trying to utilize these DataSets (and the entirety of ADO to work for me) and basically with AdHoc queries Import an excel spreadsheet, but instead of importing it directly to the DB (with an INSERT statement) i decided it might be appropriate to import it into my Typed Data Table, since I can map the columns (or so I would hope)

Now, not all the columns from my typed data table are there, and the columns in the XLS file are named differently so I'm using a SELECT statement with Aliases, and then attempting to execute a TableAdapter.Fill() on my typed datatable. I got a constraint exception.

Now this very well could be a standard constraint error, (maybe duplicates of the primary key, dunno, still investigating) but in relation to this issue I began to investigate to determine what constraint I could possibly be violating.

That's when I noticed the NullValue property in the dataset designer for my columns and they are all defaultly set to (Throw Exception).

So what exactly is NullValue (as the help says it isn't a member of the DataColumn, and the tool tip is less informative than that).

Does it mean:
DataTable.Column(i) = Null / Nothing / DBNull

Does that cause the exception?

Using a DataReader to read it from the DB and in the DB the field is DBNULL does that throw the exception?

Setting it to Nothing, does that mean I can say:
DataTable.Column(i) = Nothing

and the dataTable will translate that to an Empty or DBNull value for the database?

Thanks for clearing this up for me.
 
Action on Null Value is the action that will take place when attempting to read the value from that column in a particular row if the value is null

A datatable has one column "A" of type string. There is only one row, in the table and the value of A on that row is DBNull. You have 3 choices:

Empty
null
(expection)

when you write the code:

Dim s as string = dt(0).A

for "Empty action" s = ""
for "null action" s = Nothing
for "(exception) action" code halts with a "The Value of A in [this row] is DBNull"


-

Choose the action dependent on your circumstances
 
Back
Top