By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,480 Members | 1,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,480 IT Pros & Developers. It's quick & easy.

Computed Columns in dataset always returning NULL

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.