How to trap DBNull?

  • Thread starter Thread starter cjobes
  • Start date Start date
C

cjobes

Hi all,

I have a date field in a temp table as part of a DataSet. In some records
the value is DBNull. how can I trap the error with
if dtTemp("When") = ??? Then.....

Thanks,

Claus
 
Hi all,

I have a date field in a temp table as part of a DataSet. In some records
the value is DBNull. how can I trap the error with
if dtTemp("When") = ??? Then.....


If dtTemp("When") is system.dbnull.value then
Msgbox("oops dbnull!")
end if
 
Thanks, that worked.

Now that the project doesn't time out anymore, I found another problem.
Where the dtTemp("When") column is not DBNull I need to replace the value of
another column (dtTemp("When2") with a value of a specific variable.
Rows.Add doesn't work (although the books say that if the PK value for the
record is already there it would replace the data) and there isn't anything
like "change" or "replace". How can I do this?

Thanks,

Claus
 
You Need to Edit the ItemArray associated with that row.

Also Rows.Add does work in a round about way

Dim DT As New Data.DataTable
Dim DR As Data.DataRow
DR = DT.NewRow
DR.ItemArray(0) = "Test"
DR.ItemArray(1) = "Test2"
DT.Rows.Add(DR)


cjobes said:
Thanks, that worked.

Now that the project doesn't time out anymore, I found another problem.
Where the dtTemp("When") column is not DBNull I need to replace the value of
another column (dtTemp("When2") with a value of a specific variable.
Rows.Add doesn't work (although the books say that if the PK value for the
record is already there it would replace the data) and there isn't anything
like "change" or "replace". How can I do this?

Thanks,

Claus
 
When I try this I get an error msg that the row already belongs to the
table. I also to update the item by assigning the new value to
TableX.ItemArray(3)="new value"
One column is configured as PK auto.

bblyth said:
You Need to Edit the ItemArray associated with that row.

Also Rows.Add does work in a round about way

Dim DT As New Data.DataTable
Dim DR As Data.DataRow
DR = DT.NewRow
DR.ItemArray(0) = "Test"
DR.ItemArray(1) = "Test2"
DT.Rows.Add(DR)
 
Claus,

Why would you add a row when you have to change an item in a column.
To give some explanation about items and columns.

A column is the description of a datatable column in such a column are items
Therefore
\\\
dim mycolumname as string = mytable.columns(0).columnname
///
gives you the name of the column
\\\
dim mycolumnitem as string = mytable.rows(0).item(0) or
dim mycolumnitem as string = mytable.rows(0).item(mycolumnname)
///
Gives you the first item in the first row

Therefore you need probably something as
\\\
mytable.rows(0).item(0) = myvalue
///
I hope this helps?

Cor

cjobes said:
Thanks, that worked.

Now that the project doesn't time out anymore, I found another problem.
Where the dtTemp("When") column is not DBNull I need to replace the value
of
another column (dtTemp("When2") with a value of a specific variable.
Rows.Add doesn't work (although the books say that if the PK value for the
record is already there it would replace the data) and there isn't
anything
like "change" or "replace". How can I do this?

Thanks,

Claus
 

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

Back
Top