Null Value of Type

M

Miro

I am looping through a table trying to set a system.dbnull.value to be a ""
or whatever the equivilent of "" to the column type is...
'If statement above realizing the
myrow(colno-1) is a system.dbnull.value
Dim bla As Type = myCol.DataType
myrow(ColNo - 1) = CType("", bla)

that however does not like the "bla" in the ctype code.

How do you change the value of a column to a 'blank' / 0 / empty value of
the proper date type?

Thanks,

Miro
 
A

Armin Zingler

Miro said:
I am looping through a table trying to set a system.dbnull.value to be a ""
or whatever the equivilent of "" to the column type is...
'If statement above realizing the
myrow(colno-1) is a system.dbnull.value
Dim bla As Type = myCol.DataType
myrow(ColNo - 1) = CType("", bla)

that however does not like the "bla" in the ctype code.

How do you change the value of a column to a 'blank' / 0 / empty value of
the proper date type?

It depends on the type (-> Select Case). For example, what is a 'blank' with a Date column?


Armin
 
M

Miro

Ahh so you are saying i have to create my own 'sub' with my own case
statements.

I thought there would be something like
if there was a string with a value of "" then "".tostring would be
zero

and so on...
( something other than dbnull's )
 
A

Armin Zingler

Miro said:
Ahh so you are saying i have to create my own 'sub' with my own case
statements.
From what I know now, yes.
I thought there would be something like
if there was a string with a value of "" then "".tostring would be
zero

What is zero in this case? Only you know the value depending on the type.
That's why I asked how you want to handle the DateTime type.
and so on...
( something other than dbnull's )


Armin
 
M

Miro

I was kinda hoping vb.net had/allowed a date value of date( " / /
" )

but i see now that it does not ...

it is either null or a value.

I have coded around it ... :(
 
P

Patrice

If you don't want do distinguish between dbnull and the default value for
the same type I would just not use null in the first place. This way you
don't have any mapping to do (except perhaps for dates as having DBNull is
likely more easier than using the default value)...
 
M

Miro

I was importing an excel spreadsheet into a table.

Because of that, i dont know what the 'type' of the cell is until after the
excel table has been read.

From here as I was looping through the datarows ripping out the data I
required, I ran into the null values.
I had no issue putting "" in the string columns
0 in the numeric/double columns

but i wanted to leave some columns 'blank' in the date column and was going
about it the wrong way.

Miro
 
P

Patrice

Note also that sometimes the driver does an improper job at guessing the
types as by default it checks only the 8 first rows. Then you can get NULL
values when the underlying value is actually something else.

I believe I saw an advice about using an IMEX option that forces thte driver
to retrieve the raw text found in the Excel cells. Then you can handle the
whole conversion rather than relying on the driver first step...

A quick search about IMEX gave :

http://support.microsoft.com/kb/194124/en-us

You may want to check if it still applies...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top