Computed Columns in dataset always returning NULL

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

I am relativly new to visual basic, so this may be a no-
brainer.

I am attempting to use a computed column in a VB dataset
defined as followe:

'
'dcCost
'
Me.dcCost.ColumnName = "Cost"
Me.dcCost.DataType = GetType(System.Decimal)
Me.dcCost.Expression = "UnitPrice * Quantity"
Me.dcCost.ReadOnly = True

(IF this looks familiar, then youve probably taken MOC
2389B and done Lab 4)
So far this column only returns NULL after trying the
following:

Constructed the table and column in the visual editor.
Copied the code from the Solutions folder (cheating)
Loaded and ran the solution from the solutions folder.
Changed the expression to "6 + 3" to eleminate any
references to other columns.
Ran the code on another system with visual studio
installed.

I'm running Visual Studio.net 2003 and .net Framework 1.1.
Has anyone else encountered this or know the magic switch
to throw to enable the computed columns ?

Thanks,
Dave.
 
Hi Dave:


Dave said:
I am relativly new to visual basic, so this may be a no-
brainer.

I am attempting to use a computed column in a VB dataset
defined as followe:

'
'dcCost
'
Me.dcCost.ColumnName = "Cost"
Me.dcCost.DataType = GetType(System.Decimal)
Me.dcCost.Expression = "UnitPrice * Quantity"
Me.dcCost.ReadOnly = True

(IF this looks familiar, then youve probably taken MOC
2389B and done Lab 4)
So far this column only returns NULL after trying the
following:

Constructed the table and column in the visual editor.
Copied the code from the Solutions folder (cheating)
Loaded and ran the solution from the solutions folder.
Changed the expression to "6 + 3" to eleminate any
references to other columns.
Ran the code on another system with visual studio
installed.

I'm running Visual Studio.net 2003 and .net Framework 1.1.
Has anyone else encountered this or know the magic switch
to throw to enable the computed columns ?

Are you sure you have valid values in there? I'm thinking you may have
nulls and any operation on null = null. It doesn't equal anythign not even
Null or itself

This code works like a charm for me ( I created a table with Quantity and
Price as columns:

Dim ds As New DataSet
da2.Fill(ds, "PriceQuantity")
Dim dcTotal As New DataColumn("TotalPrice",
System.Type.GetType("System.Decimal"))
dcTotal.Expression = "Price * Quantity"
dcTotal.ReadOnly = True 'Don't really need this
ds.Tables(0).Columns.Add(dcTotal)
DataGrid1.DataSource = ds.Tables(0)
 
Back
Top