473,326 Members | 2,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Expressions in a Datatable

Hello everyone

Here is what I am trying to do

I have a datatable with 7 columns (called Mon, Tue, Wed,...) representing the days of the week

I want to create a calculated column called totals that totals the 7 days of the week columns

I try to use the following code

Dim cTotal As DataColumn
cTotal = New DataColumn
With cTotal
.DataType = System.Type.GetType("System.Decimal")
.ColumnName = "First Totals"
.Expression = "Sun + Mon + Tue + Wed + Thu + Fri + Sat"
End With
dt.Columns.Add(cTotal)

But it does not work.

If I put in the following as the expression the column calculates fine

..Expression = "Sun + Mon"

Is it possible for me to add the values of 7 columns into 1 totals column?

Thanks

Corey
Jul 21 '05 #1
1 1409
Update,

I now know why my code was not working

When I was doing my calcluation expression, I was not checking to see if a column had nulls in it.

I changed the expression to look like this:

.Expression = "IsNull(Sun,0) + IsNull(Mon,0) + IsNull(Tue,0) + IsNull(Wed,0) + IsNull(Thu,0) + IsNull(Fri,0) + IsNull(Sat,0)"

And now it works!
"Coreymas" wrote:
Hello everyone

Here is what I am trying to do

I have a datatable with 7 columns (called Mon, Tue, Wed,...) representing the days of the week

I want to create a calculated column called totals that totals the 7 days of the week columns

I try to use the following code

Dim cTotal As DataColumn
cTotal = New DataColumn
With cTotal
.DataType = System.Type.GetType("System.Decimal")
.ColumnName = "First Totals"
.Expression = "Sun + Mon + Tue + Wed + Thu + Fri + Sat"
End With
dt.Columns.Add(cTotal)

But it does not work.

If I put in the following as the expression the column calculates fine

.Expression = "Sun + Mon"

Is it possible for me to add the values of 7 columns into 1 totals column?

Thanks

Corey

Jul 21 '05 #2

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

Similar topics

5
by: Stefan Turalski \(stic\) | last post by:
Hi, I'm wondering if there is a way to send a method parametrs by ref when DataTabel is a type of this value ? I done some sort of select over DataTable columns, just by removing them froma...
4
by: MrNobody | last post by:
I really need to use the "&" logical operator on a data column when using FilterRow, but apparantly the filter expressions do not support this. Is there any workaround for this?
3
by: KC | last post by:
I created a dataset at design time, filled it with tables, and the tables with columns. One of the columns in each table contains an expression (I just concatenated 3-4 columns from the same...
7
by: Raymond Lewallen | last post by:
Which would be the proper way or the reason for using any of the following or combinations of the following? These are the 3 ways I've figured I can do what I want to do, I just don't know which...
3
by: Gene Hubert | last post by:
I'm using DataTable.ImportRow to move data from one datatable to another... Dim dt, dtTarget As DataTable Dim dr As DataRow dt = DirectCast(Me.DataSource, DataTable) dtTarget = dt.Clone...
1
by: Engineerik | last post by:
According to what I see in the manuals I should be able to use regular expressions with the rowfilter property of a dataview but I keep getting errors. Example: I want to find any rowview where...
1
by: Coreymas | last post by:
Hello everyone Here is what I am trying to do I have a datatable with 7 columns (called Mon, Tue, Wed,...) representing the days of the week I want to create a calculated column called...
0
by: G .Net | last post by:
Hi I've run into a problem when using Expressions in a DataColumn of a DataTable which I'm updating back to the underlying databas. That is, I'm loading data into a DataTable in which I've set...
1
by: Tarun Mistry | last post by:
Hi all, I have a DataTable im trying to filter, however I simply cannot get what appears to be a simply expression to work. Int cartId = 15; string expression = "cartId =" + cartId; DataRow...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.