472,805 Members | 3,559 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

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

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
0 4355

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: JMorrell | last post by:
Hi all. I have a situation where I needed to add a new column to a view coming over from a SQL Server. The code to add the column is as follows: ' new column for Sick Hours Sum Dim...
2
by: rawCoder | last post by:
Hi All, I have a column in my datatable that is named like a number i.e. 45 I know its not good to have a column named as number, but... Anyways, so when i set the DataView's RowFilter to...
3
by: J | last post by:
Is there anyway to format a calculated datacolumn? I would like the following column to display as money (formatted as $#,##0.00). Or how about simply displaying the column formatted as a number...
1
by: John E. | last post by:
I have a datagrid with one column that is boolean (it is a checkbox column). So that myDataTable.Column..DataType.UnderlyingSystemType == System.Boolean. For printing purposes, I would like to...
1
by: Azkaban | last post by:
Hi I succeded to add a DataColumn to DataSet but now I've one big problem. The value of this column would be a personal function result, I try a lot of time but the result is always empty. Why?...
5
by: Larry Bird | last post by:
I've created a AlertDataClass below within the class I have tables and column that I've create. In the AlertDataAccess class I'm trying to insert data into my tables. AlertDataAccess is a Module...
4
by: bordsby | last post by:
Situation: I am using an OleDbDataAdapter to fill a DataSet's DataTable with data from an Access database. The DataSet's DataTable is bound to a DataGrid. After the OleDbDataAdapter.Fill method...
11
by: Matt F | last post by:
I'm trying to do something that seems like it should be pretty simple, but haven't found a solution. I am trying to add a datacolumn to a datatable that adds or subtracts a number of days based on...
3
by: Manuel | last post by:
Hi to all, I'm trying to copy a Datacolumn from a table to another, but with this code: destTable.Columns.Add(srcTable.Column); I got this error: Column 'colname' already belongs to another...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.