473,545 Members | 1,994 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=StartDa te 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 1939
Here is an example of adding a column to a datatable this is based on two
other columns

Dim myDataColumn As DataColumn= new datacolumn("Shi pDisplay")
myDataColumn.da tatype=System.T ype.GetType("Sy stem.String")
myDataColumn.ex pression = ("Descriptio n + ' 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@winterminut e.com.NOSPAM> wrote in message
news:Od******** ******@TK2MSFTN GP12.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=StartDa te 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.e xpression=" that I could set
the value of the new column to a string value?
"vMike" <Mi************ ****@noYandZ.ge ZwaYrrenZ.com> wrote in message
news:bu******** **@ngspool-d02.news.aol.co m...
Here is an example of adding a column to a datatable this is based on two
other columns

Dim myDataColumn As DataColumn= new datacolumn("Shi pDisplay")
myDataColumn.da tatype=System.T ype.GetType("Sy stem.String")
myDataColumn.ex pression = ("Descriptio n + ' 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@winterminut e.com.NOSPAM> wrote in message
news:Od******** ******@TK2MSFTN GP12.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=StartDa te 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)("you rnewcolumnname" ) = 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@winterminut e.com.NOSPAM> wrote in message
news:u1******** ******@TK2MSFTN GP11.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.e xpression=" that I could set
the value of the new column to a string value?
"vMike" <Mi************ ****@noYandZ.ge ZwaYrrenZ.com> wrote in message
news:bu******** **@ngspool-d02.news.aol.co m...
Here is an example of adding a column to a datatable this is based on two
other columns

Dim myDataColumn As DataColumn= new datacolumn("Shi pDisplay")
myDataColumn.da tatype=System.T ype.GetType("Sy stem.String")
myDataColumn.ex pression = ("Descriptio n + ' 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@winterminut e.com.NOSPAM> wrote in message
news:Od******** ******@TK2MSFTN GP12.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=StartDa te 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
3055
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 record such as: part number 202354-001 location C1-01
1
2085
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, Attended I can easily create new Events and Elients, however, when i create a
13
2651
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 one to one relationship between the two tables. I have a form for the parts. It includes 25 text boxes for both the part numbers and the...
1
3265
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 days of struggling, I figure asking you all (the experts) will keep me from going down some dark and dangerous road. The project I have is a fairly...
10
2320
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 the DataAdd part (Section heading is Adding Rows to a DataSet) I dont really know what to do after i have added all the
8
1896
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 other users in the database. I keep getting the message 'Operation must use an updateable query.' Process seems to work on some PC's, not others. Is...
16
2459
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 it with incremental values e.g. if the tables looks like this: 23 56
14
2352
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 tedious typing a lot of these.
0
4429
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 attachment contains the complete source code which was explained in the previous article parts. Download it, extract the sources somewhere and have a look....
0
7475
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7664
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7921
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7437
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5982
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3465
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1900
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
720
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.