Null values creating problem

  • Thread starter Thread starter arun
  • Start date Start date
A

arun

Hi
I have a table having Null values for some columns.
When ever I read it through a data reader, like
Convert.ToInt32(dr("Column")) I am getting some error.

1.How to handle this situation, especially with integer nulls

2.While updating a record, If I am not modifying some of these null
values, I want the column to show null only in the table. Is it
possible.
 
1) Use the IsDBNull function to test for NULL.

2) Not sure to understand what you meant ? What is "the table" ? (DataTable,
table DB Side ?). If you don't update your self the value in the DataTable,
it will be left unchanged, it will be left unchanged (you can also how NULL
is displayed in your grid without chanhging the value in the DataTable if
this is what you had in mind)...
 
Hi
I have a table having Null values for some columns.
When ever I read it through a data reader, like
Convert.ToInt32(dr("Column")) I am getting some error.

1.How to handle this situation, especially with integer nulls

2.While updating a record, If I am not modifying some of these null
values, I want the column to show null only in the table. Is it
possible.

I think you want to check out the System.DBNull object. It's provided for
this purpose.

ex

If Not dr(0).Value Is DBNull.Value Then DoSomething() 'Get data

or

If intI = 0 then dtTable.Rows(0)(0).Value = DBNull.Value 'Put data

Unfortunately I don't think there's an easier way, but so long as you
enfornce tight constraints on your database tables and allow null values
only when necessary it can be relatively quick to scipt up a proc to
process values from a reader.
 
Back
Top