469,313 Members | 2,636 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,313 developers. It's quick & easy.

Computed Columns in dataset always returning NULL

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.
Nov 20 '05 #1
1 1737
Hi Dave:
"Dave" <an*******@discussions.microsoft.com> wrote in message
news:0d****************************@phx.gbl...
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)
Thanks,
Dave.

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by DMAC | last post: by
4 posts views Thread by Henning N?rg?rd | last post: by
4 posts views Thread by Brad Baker | last post: by
7 posts views Thread by Aamir Mahmood | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.