473,396 Members | 1,996 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,396 software developers and data experts.

Populating a data grid with a calculated field...

Hello All,

I have the following query...

SELECT Demographics.Full_Name,
Demographics.Year_of_birth,
Status.Status_OK,
SUM(2004 - Demographics.Year_of_birth) AS Age
FROM Demographics
INNER JOIN Status ON Demographics.PrimaryKey = Status.PrimaryKey
GROUP BY Demographics.Full_Name, Demographics.Year_of_birth,
Status.Status_OK

I also have a grid on VB ASP.NET web form which is boound to this query that
has 3 columns
Full Name, Year of Birth and Status

How can I create a 4th column in the data grid to display the age that is
returned by the query in VS.NET 2003?

I'm new to .NET

Thanks,

-U
Nov 21 '05 #1
2 5991
Hi
you can build your datatable object , add your four columns to it then
bind it to the datagrid.
You can build your datatable as follows :

Dim parent As new DataTable("Parent");
parent.Columns.Add(new DataColumn("name", typeof(string)));
parent.Columns.Add(new DataColumn("year_of_birth", typeof(decimal)));
parent.Columns.Add(new DataColumn("status", typeof(string)));
parent.Columns.Add(new DataColumn("age", typeof(decimal)));

parent.PrimaryKey = new DataColumn[] { parent.Columns["name"] };

bound the three first columns Then for the forth columns that will be
calculated add the appropriate expression that would return the calculated
age
parent.Columns["age"].Expression =
"you may but your query ";

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 21 '05 #2
Mohamoss & unforgiven,
typeof is a C# operator, in VB.NET you need to use the GetType operator (not
to be confused with the Object.GetType & Type.GetType methods). Also [] is
C#:

Dim parent As New DataTable("Parent")
parent.Columns.Add(New DataColumn("name", GetType(string)))
parent.Columns.Add(New DataColumn("year_of_birth", GetType(decimal)))
parent.Columns.Add(New DataColumn("status", GetType(string)))
parent.Columns.Add(New DataColumn("age", GetType(decimal)))

parent.PrimaryKey = New DataColumn() { parent.Columns("name") }

I normally include the expression on the New DataColumn constructor, rather
then set Expression explicitly, either works.

parent.Columns.Add(new DataColumn("age", GetType(decimal), "the
expression"))

For information on expressions in the DataSet object model see the
DataColumn.Expression help topic.

http://msdn.microsoft.com/library/de...ssiontopic.asp

Hope this helps
Jay
"Mohamoss" <mo************@egdsc.microsoft.com> wrote in message
news:Aw**************@cpmsftngxa06.phx.gbl...
Hi
you can build your datatable object , add your four columns to it then
bind it to the datagrid.
You can build your datatable as follows :

Dim parent As new DataTable("Parent");
parent.Columns.Add(new DataColumn("name", typeof(string)));
parent.Columns.Add(new DataColumn("year_of_birth", typeof(decimal)));
parent.Columns.Add(new DataColumn("status", typeof(string)));
parent.Columns.Add(new DataColumn("age", typeof(decimal)));

parent.PrimaryKey = new DataColumn[] { parent.Columns["name"] };

bound the three first columns Then for the forth columns that will be
calculated add the appropriate expression that would return the calculated
age
parent.Columns["age"].Expression =
"you may but your query ";

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 21 '05 #3

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

Similar topics

7
by: Jack | last post by:
Hi, I have posted this problem before. Apprently, the suggestion took care of the problem. However, still I am getting the above error message. I am using a session variable to transfer a value...
3
by: sao | last post by:
I am currently using Access 2000. In my table it is the following fields that are set up: 1 - Staff Name 2 - Department This table is already populated with 100+ records (staff along with...
3
by: ssb | last post by:
Hello, This may be very elementary, but, need help because I am new to access programming. (1) Say, I have a column EMPLOYEE_NAME. How do I fetch (maybe, cursor ?) the values one by one and...
1
by: shobhit_shanker | last post by:
Here are the relevant "givens" to my problem... Form: frmLaunchRpt - Text Box: txtAsOfDate - Check Box: chkLogEval - Command Button: cmdLaunchRpt Report: rptEvaluation - Text Box:...
1
by: tconway | last post by:
I have an Access program that displays Customer data into a form and OrderID data into a subform. The totals in the Subform are based on calculated fields, i.e. the Total Amount field Calculates...
2
by: Josef Meile | last post by:
Hi, I'm using a ComboBox, some Textboxes, and a DataGrid to represent a many-to-many relationship between Person and Course. Each time that I change the value in the ComboBox (which for now is...
5
by: Brian P. Hammer | last post by:
I have data from multiple SQL tables, some of the tables will only have one row, while others multiple rows. I load a bunch of data from the various tables and add them to a third party grid. With...
6
by: sara | last post by:
I have what I think is a little strange...I have to get data from our payroll system into a specific format (fixed record length) as a .txt or .prn file only to upload to our 401k custodian. I...
0
by: =?Utf-8?B?S3VydCBvZiBTYW4gSm9zZQ==?= | last post by:
All- Please advise as to what's the best way to display data in a column in a grid view (and I'm using a dataset) in a table (say TABLE2) which: - is non-zero only if a boolian field in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.