PC Review


Reply
Thread Tools Rate Thread

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

 
 
SMH
Guest
Posts: n/a
 
      14th Oct 2007
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
------------

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Column <ColumnName> does not belong to table <TableName> Cor Ligthert [MVP] Microsoft ADO .NET 11 4th May 2011 01:50 AM
How to GetDecimal from database by ColumnName (NOT: by column number) ? Mark Poppers Microsoft C# .NET 4 12th Jun 2007 01:42 AM
DataTable Column Index for Given ColumnName =?Utf-8?B?ZGNobWFu?= Microsoft ADO .NET 6 25th Feb 2007 05:57 PM
DataColumn Expression Q Vai2000 Microsoft C# .NET 1 4th Mar 2005 02:00 PM
DataColumn.Expression error handling =?Utf-8?B?cGFsaQ==?= Microsoft ADO .NET 4 1st Jul 2004 02:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:10 PM.