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

Adding Data To a Table That Isn't Part Of the Original SQL Query

I am fairly new to ASP.NET so I think I am missing something fundamental.
Anyway, quite often I am pulling data from a database, but then I need to
use that data to produce more data. A simple example would be: Let's say
Column1=StartDate and Column2=EndDate. In addition to displaying Column1 and
Column2, I need to do some calculations and display in as Column3.

The calculations are easy and can be done in the code-behind. How to display
it is another question.
However, they might not be math calculations. Take for example, a SQL query
that returns a list of servers and then for each server I use WMI to get
some additional information and then I need to display the servername (from
SQL) and the OS and Service Pack Version (from WMI) on a web page.

The way I have been handling it is creating a new table in memory and adding
the columns from the original SQL query and then doing the calculations and
adding that as a column. Then I'll use this new table to DataBind my
DataGrid or DataList.

Is this the best way to do it? I feel like this isn't the smartest way to
acomplish this.
Nov 18 '05 #1
3 1929
Here is an example of adding a column to a datatable this is based on two
other columns

Dim myDataColumn As DataColumn= new datacolumn("ShipDisplay")
myDataColumn.datatype=System.Type.GetType("System. String")
myDataColumn.expression = ("Description + ' cost $' + Charge")
dt.columns.add(myDatacolumn)

Please note that the expression not an asp.net statement, it is like a
database statement. In the above example the expression is the data in the
Description column concatenated with the word 'cost $' and data in the
Charge column. So if I had and row item in my table with the Description
'Express' and the Charge column was "20" then the new column would display
'Express cost $20' for that data row. I don't think you can use variables
(except for constant strings) in the expression statement. You can use math
and other functions like you would in a database statement but it has to be
based on the columns of the data base.

Hope this helps.

"Robin Thomas" <me@winterminute.com.NOSPAM> wrote in message
news:Od**************@TK2MSFTNGP12.phx.gbl...
I am fairly new to ASP.NET so I think I am missing something fundamental.
Anyway, quite often I am pulling data from a database, but then I need to
use that data to produce more data. A simple example would be: Let's say
Column1=StartDate and Column2=EndDate. In addition to displaying Column1 and Column2, I need to do some calculations and display in as Column3.

The calculations are easy and can be done in the code-behind. How to display it is another question.
However, they might not be math calculations. Take for example, a SQL query that returns a list of servers and then for each server I use WMI to get
some additional information and then I need to display the servername (from SQL) and the OS and Service Pack Version (from WMI) on a web page.

The way I have been handling it is creating a new table in memory and adding the columns from the original SQL query and then doing the calculations and adding that as a column. Then I'll use this new table to DataBind my
DataGrid or DataList.

Is this the best way to do it? I feel like this isn't the smartest way to
acomplish this.

Nov 18 '05 #2
Yes, this helps very much. What if I didn't want that column to be a
calculation based on other columns (as your example shows), but rather
additional information for that record.

Is there something other than "myDataColumn.expression=" that I could set
the value of the new column to a string value?
"vMike" <Mi****************@noYandZ.geZwaYrrenZ.com> wrote in message
news:bu**********@ngspool-d02.news.aol.com...
Here is an example of adding a column to a datatable this is based on two
other columns

Dim myDataColumn As DataColumn= new datacolumn("ShipDisplay")
myDataColumn.datatype=System.Type.GetType("System. String")
myDataColumn.expression = ("Description + ' cost $' + Charge")
dt.columns.add(myDatacolumn)

Please note that the expression not an asp.net statement, it is like a
database statement. In the above example the expression is the data in the
Description column concatenated with the word 'cost $' and data in the
Charge column. So if I had and row item in my table with the Description
'Express' and the Charge column was "20" then the new column would display
'Express cost $20' for that data row. I don't think you can use variables
(except for constant strings) in the expression statement. You can use math and other functions like you would in a database statement but it has to be based on the columns of the data base.

Hope this helps.

"Robin Thomas" <me@winterminute.com.NOSPAM> wrote in message
news:Od**************@TK2MSFTNGP12.phx.gbl...
I am fairly new to ASP.NET so I think I am missing something fundamental. Anyway, quite often I am pulling data from a database, but then I need to use that data to produce more data. A simple example would be: Let's say
Column1=StartDate and Column2=EndDate. In addition to displaying Column1

and
Column2, I need to do some calculations and display in as Column3.

The calculations are easy and can be done in the code-behind. How to

display
it is another question.
However, they might not be math calculations. Take for example, a SQL

query
that returns a list of servers and then for each server I use WMI to get
some additional information and then I need to display the servername

(from
SQL) and the OS and Service Pack Version (from WMI) on a web page.

The way I have been handling it is creating a new table in memory and

adding
the columns from the original SQL query and then doing the calculations

and
adding that as a column. Then I'll use this new table to DataBind my
DataGrid or DataList.

Is this the best way to do it? I feel like this isn't the smartest way to acomplish this.


Nov 18 '05 #3
Well you can set it to some contant value here. Otherwise you add the column
with no expression statement and then
you will have to iterate through the entire datatable and add a value to
each row using a for i = 0 to dt.rows.count - 1 ..
dt.rows(i)("yournewcolumnname") = i (or somevalue) ... next i . (this is
common for adding sequential row numbers to the datatable) This will have
to be done every time you create the datatable unless you are able to save
the table in a database or xml file.

"Robin Thomas" <me@winterminute.com.NOSPAM> wrote in message
news:u1**************@TK2MSFTNGP11.phx.gbl...
Yes, this helps very much. What if I didn't want that column to be a
calculation based on other columns (as your example shows), but rather
additional information for that record.

Is there something other than "myDataColumn.expression=" that I could set
the value of the new column to a string value?
"vMike" <Mi****************@noYandZ.geZwaYrrenZ.com> wrote in message
news:bu**********@ngspool-d02.news.aol.com...
Here is an example of adding a column to a datatable this is based on two
other columns

Dim myDataColumn As DataColumn= new datacolumn("ShipDisplay")
myDataColumn.datatype=System.Type.GetType("System. String")
myDataColumn.expression = ("Description + ' cost $' + Charge")
dt.columns.add(myDatacolumn)

Please note that the expression not an asp.net statement, it is like a
database statement. In the above example the expression is the data in the Description column concatenated with the word 'cost $' and data in the
Charge column. So if I had and row item in my table with the Description
'Express' and the Charge column was "20" then the new column would display 'Express cost $20' for that data row. I don't think you can use variables (except for constant strings) in the expression statement. You can use

math
and other functions like you would in a database statement but it has to

be
based on the columns of the data base.

Hope this helps.

"Robin Thomas" <me@winterminute.com.NOSPAM> wrote in message
news:Od**************@TK2MSFTNGP12.phx.gbl...
I am fairly new to ASP.NET so I think I am missing something fundamental. Anyway, quite often I am pulling data from a database, but then I need to use that data to produce more data. A simple example would be: Let's say Column1=StartDate and Column2=EndDate. In addition to displaying Column1 and
Column2, I need to do some calculations and display in as Column3.

The calculations are easy and can be done in the code-behind. How to

display
it is another question.
However, they might not be math calculations. Take for example, a SQL

query
that returns a list of servers and then for each server I use WMI to
get some additional information and then I need to display the servername

(from
SQL) and the OS and Service Pack Version (from WMI) on a web page.

The way I have been handling it is creating a new table in memory and

adding
the columns from the original SQL query and then doing the
calculations and
adding that as a column. Then I'll use this new table to DataBind my
DataGrid or DataList.

Is this the best way to do it? I feel like this isn't the smartest way

to acomplish this.



Nov 18 '05 #4

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

Similar topics

6
by: 6thirty | last post by:
Hi, I've created a stocktaking database using Access XP. This is indexed by two fields - part number and shelf location. I am currently inputting all the data via a form. When I have entered a...
1
by: Alec Christie | last post by:
Hi All, I currently have 3 tables, Clients, Events and Event Status as follows: Clients: ClientID, Name, Address Events: EventID, Name, Date Event Status: StatusID, EventID, ClientID,...
13
by: Shannan Casteel via AccessMonster.com | last post by:
I set up two tables (one with the regular claim info and another with ClaimNumber, PartNumber, and QuantityReplaced). The ClaimNumber is an autonumber and the primary key in both tables. I made a...
1
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
10
by: Trevor | last post by:
Hey, I am trying to do this tutorial on the microsoft site : http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dndotnet/html/usingadonet.asp I can get everything to work up to...
8
by: rriness | last post by:
I'm getting an inconsistent failure when trying to save data in ADO.Net. I'm using an Access database with a simple query - SELECT StudentID, FirstName, LastName FROM Students - and have no...
16
by: Geoff Jones | last post by:
Hi Can anybody help me with the following, hopefully simple, question? I have a table which I've connected to a dataset. I wish to add a new column to the beginning of the table and to fill...
14
by: Karl Irvin | last post by:
While adding data to a record set, I use something like rst! = some variable rst! = some variable ...... rst! = some variable The rst! , rst! etc. are manually typed in and it gets...
0
by: JosAH | last post by:
Greetings, Introduction Last week I was a bit too busy to cook up this part of the article series; sorry for that. This article part wraps up the Text Processing article series. The ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.