How to handle nulls in this expression?

  • Thread starter Thread starter dbuchanan
  • Start date Start date
D

dbuchanan

Hello,

I am selectively copying existing column data into a new data row
using. Sometimes a column is null. How do I handle nulls in the
following expression?

new020VersionRow.PartMarkingSystems =
CByte(drv020Version("PartMarkingSystems"))

Thank you,
dbuchanan
 
Hi,

dbuchanan said:
Hello,

I am selectively copying existing column data into a new data row
using. Sometimes a column is null. How do I handle nulls in the
following expression?

new020VersionRow.PartMarkingSystems =
CByte(drv020Version("PartMarkingSystems"))

Probely something like:

If ( drv020Version("PartMarkingSystems") Is DBNull.Value ) Then
new020VersionRow.SetPartMarkingSystemsNull()
Else
new020VersionRow.PartMarkingSystems = _
CByte(drv020Version("PartMarkingSystems"))
End If

HTH,
Greetings
 
Hi Bart,

Thank you.

I was hoping for a one-liner since I have a lot of these.

Is there a way to create a method maybe that I can put in a module that
can perform this conditional check? I have thought it through but
cannot figure out how to build it.

Maybe the call could look like this...

CheckForNull("PartMarkingSystes", byte, new020Version, drv020Version)


dbuchanan
 
Hi,

dbuchanan said:
Hi Bart,

Thank you.

I was hoping for a one-liner since I have a lot of these.

Is there a way to create a method maybe that I can put in a module that
can perform this conditional check? I have thought it through but
cannot figure out how to build it.

Maybe the call could look like this...

CheckForNull("PartMarkingSystes", byte, new020Version, drv020Version)

You could also use:

new020VersionRow("PartMarkingSystems") = _
drv020Version("PartMarkingSystems")

HTH,
Greetings
 
Bart,

Are you still listening? This is related to the same code block.

Question #1
In a new row I can refer to the "PartMarkingSystems" column like this

new020VersionRow.PartMarkingSystems

and the column is recognized by intellisense. However in the following
statement the same column is *not* recognized by intellisense.

drv020Version("PartMarkingSystems")

Is there a way to refer to that column in such a way that it *is*
recognized by intellisense?

I would like to update a couple of columns in the current rwo without
having to create a bound control and (for future reference) I would
like to be able to do it without having to look up the column name in
the database.

Here is the code I know how to write using bound controls;

'Declare a vaiable to hold the current row of the BindingSource
Dim drv020Version As DataRowView =
DirectCast(Me.Tbl020VersionBindingSource.Current, DataRowView)

drv020Version("verEditedOnLabel1") = CStr(Now)
drv020Version("VerEditedByLabel1") = GetUserName()


Thank you,
dbuchanan
 
Hi,

dbuchanan said:
Bart,

Are you still listening? This is related to the same code block.

Question #1
In a new row I can refer to the "PartMarkingSystems" column like this

new020VersionRow.PartMarkingSystems

and the column is recognized by intellisense. However in the following
statement the same column is *not* recognized by intellisense.

drv020Version("PartMarkingSystems")

Is there a way to refer to that column in such a way that it *is*
recognized by intellisense?

I would like to update a couple of columns in the current rwo without
having to create a bound control and (for future reference) I would
like to be able to do it without having to look up the column name in
the database.

Here is the code I know how to write using bound controls;

'Declare a vaiable to hold the current row of the BindingSource
Dim drv020Version As DataRowView =
DirectCast(Me.Tbl020VersionBindingSource.Current, DataRowView)

drv020Version("verEditedOnLabel1") = CStr(Now)
drv020Version("VerEditedByLabel1") = GetUserName()

I guess something like this should work:

Dim drv020Version As DataRowView = _
DirectCast( Me.Tbl020VersionBindingSource.Current, DataRowView )

Dim dr020Version As YourDataSet.Tbl020VersionRow = _
DirectCast( drv020Version.Row, YourDataSet.Tbl020VersionRow )

dr020Version.verEditedOnLabel1 = CStr(Now)
dr020Version.verEditedByLabel1 = GetUserName()


HTH,
Greetings
 
Bart,

Thank you, but I have another question.

Here is exactly what it worked out to be;
\\
Dim drv020Version As DataRowView = _
DirectCast(Me.Tbl020VersionBindingSource.Current,
DataRowView)

Dim dr020Version As QmsDataLayer.DataSet1.tbl020VersionRow = _
DirectCast(drv020Version.Row,
QmsDataLayer.DataSet1.tbl020VersionRow)

dr020Version.verEditedOn = Now
dr020Version.verEditedBy = GetUserName()
//

Why does the code require me to fully qualify my dataset as;
QmsDataLayer.DataSet1.xxxXxxxxXxx
when "QmsDataLayer" is refetenced in this project and "DataSet1" is in
the component tray of the current form?

Thank you,
dbuchanan
 
Hi,

dbuchanan said:
Bart,

Thank you, but I have another question.

Here is exactly what it worked out to be;
\\
Dim drv020Version As DataRowView = _
DirectCast(Me.Tbl020VersionBindingSource.Current,
DataRowView)

Dim dr020Version As QmsDataLayer.DataSet1.tbl020VersionRow = _
DirectCast(drv020Version.Row,
QmsDataLayer.DataSet1.tbl020VersionRow)

dr020Version.verEditedOn = Now
dr020Version.verEditedBy = GetUserName()
//

Why does the code require me to fully qualify my dataset as;
QmsDataLayer.DataSet1.xxxXxxxxXxx
when "QmsDataLayer" is refetenced in this project and "DataSet1" is in
the component tray of the current form?

Because there is a difference between the two DataSet1's, one is a type (for
DirectCast) and the other is an instance (on the Form).

QmsDataLayer.DataSet1.tbl020VersionRow
here QmsDataLayer is a namespace, DataSet1 a class and tbl020VersionRow a
subclass.

If you put "Imports QmsDataLayer" at the top of the code file, then you
should be able to use DataSet1.tbl020VersionRow instead.

HTH,
greetings
 
Back
Top