470,822 Members | 1,397 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

DataColumn.Expression Error - 'Cannot Find Column [ColumnName]'

Hi All,

I am currently learning .Net 2, studying for 70-528. I've hit a bit of
a brick wall with DataColumn.Expression. As I understand it, this can
be used to (For example) concatenate two columns to make a derived

When I run my code, I get this error:

Cannot find column [dcLastName].
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Data.EvaluateException: Cannot find column

Source Error:

Line 75: LastNameFirstName.Expression = "dcLastName"
Line 76: LastNameFirstName.MaxLength = 70
Line 77: dtEmployee.Columns.Add(LastNameFirstName)

Below is my code, hopefully someone can tell me whats going on,
because I have followed the book and it isnt working! Have spent a
good 30 minutes Googling, could not find anything useful, so perhaps
I've made a simple mistake in there some where??

Thanks for reading!


Public Function GetDataTable() As DataTable
'Create a table
Dim dtEmployee As New DataTable("Employee")

'Add columns to define our data structure
Dim dcEID As New DataColumn("Eid")
dcEID.DataType = GetType(String)
dcEID.MaxLength = 10
dcEID.Unique = True
dcEID.AllowDBNull = False
dcEID.Caption = "EID" 'Defines the heading to use for this
column when the data is used to populate a web server control

Dim dcFirstName As New DataColumn("FirstName")
dcFirstName.MaxLength = 35
dcFirstName.AllowDBNull = False

Dim dcLastName As New DataColumn("LastName")
dcLastName.AllowDBNull = False

Dim DCguid As New DataColumn
DCguid.DataType = GetType(String)
Dim strGUID As Guid
DCguid.DefaultValue = strGUID

Dim salary As New DataColumn("salary", GetType(Decimal))
salary.DefaultValue = 0.0

'Derived column using an expression
Dim LastNameFirstName As New DataColumn("Lastname and
LastNameFirstName.DataType = GetType(String)
LastNameFirstName.Expression = "dcLastName + ', ' +
LastNameFirstName.MaxLength = 70

'Set the primary key for the table
dtEmployee.PrimaryKey = New DataColumn() {dcEID}

Return dtEmployee

End Function

Oct 14 '07 #1
0 4124

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by JMorrell | last post: by
2 posts views Thread by rawCoder | last post: by
3 posts views Thread by J | last post: by
1 post views Thread by Azkaban | last post: by
5 posts views Thread by Larry Bird | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.