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

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

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

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
[dcLastName].

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!

Simon.

------------
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
dtEmployee.Columns.Add(dcEID)

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

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

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
dtEmployee.Columns.Add(salary)

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

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

Return dtEmployee

End Function
------------

Oct 14 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.