473,503 Members | 3,740 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do i add a calculated column to a dataset?

Hi,

I have a dataset which is used to populate my datagrid something like this:
My question is, how do I add a caluclated display column to the datagrid?
It will be based on ScoreCardScore...

Dim Cmd As OleDbCommand = New OleDbCommand("Select AuditDate,
ScoreCardScore, DetailsScore from Audits where SupplierID = " &
ComboItem.Value.ToString, conn)

' create the data adapter object and pass in the sql command object

myDataAdapter = New System.Data.OleDb.OleDbDataAdapter(Cmd)

' Tell the myDataadabter to fill the dataset

myDataAdapter.Fill(myDataSet, "Name")

dgAudits.DataSource = myDataSet.Tables("Name").DefaultView

Thanks very much for any advice!

Dan
Nov 20 '05 #1
8 19521
I have not tried this, and I'm going out soon so I don't have time but . . .
..

One suggestion that you might like to try is to Add a total column before
filling the dataset. For the table containing the values to be calculated,
add a row_changed delegate. and simply put that value in the datagrid cell
each time a change is made.

Regards - OHM

Dan Keeley wrote:
Hi,

I have a dataset which is used to populate my datagrid something like
this: My question is, how do I add a caluclated display column to the
datagrid? It will be based on ScoreCardScore...

Dim Cmd As OleDbCommand = New OleDbCommand("Select AuditDate,
ScoreCardScore, DetailsScore from Audits where SupplierID = " &
ComboItem.Value.ToString, conn)

' create the data adapter object and pass in the sql command object

myDataAdapter = New System.Data.OleDb.OleDbDataAdapter(Cmd)

' Tell the myDataadabter to fill the dataset

myDataAdapter.Fill(myDataSet, "Name")

dgAudits.DataSource = myDataSet.Tables("Name").DefaultView

Thanks very much for any advice!

Dan


Regards - OHM# OneHandedMan{at}BTInternet{dot}com
Nov 20 '05 #2
Another way of solving this problem (I'm not saying it's better :-), is to
use a custom column style in the datagrid:

Data binding and Web Services using Custom Collections
http://www.microsoft.com/belux/nl/ms...cewrapper.mspx
The data binding capabilities in .NET are great, you can bind many controls
to almost any type of data, but in some scenarios data binding has its
limitations. For example data binding is not possible when using custom
collections, instead of DataSets, coming from a Web Service. This article
explains the problem and a possible, easy-to-use, solution: a class that
dynamically builds wrapper classes at run time, which exposes the field
member of the proxy classes as properties.

--
Greetz,
Jan
__________________________________
Read my weblog: http://weblogs.asp.net/jan
"Dan Keeley" <ma********@hotmail.com> schreef in bericht
news:jb****************@newsfep4-winn.server.ntli.net...
Hi,

I have a dataset which is used to populate my datagrid something like this: My question is, how do I add a caluclated display column to the datagrid?
It will be based on ScoreCardScore...

Dim Cmd As OleDbCommand = New OleDbCommand("Select AuditDate,
ScoreCardScore, DetailsScore from Audits where SupplierID = " &
ComboItem.Value.ToString, conn)

' create the data adapter object and pass in the sql command object

myDataAdapter = New System.Data.OleDb.OleDbDataAdapter(Cmd)

' Tell the myDataadabter to fill the dataset

myDataAdapter.Fill(myDataSet, "Name")

dgAudits.DataSource = myDataSet.Tables("Name").DefaultView

Thanks very much for any advice!

Dan

Nov 20 '05 #3
Untested.......

dstest.Tables(0).Columns.Add("total")
Dim i As Integer
For i = 0 To dstest.Tables(0).Rows.Count - 1
dstest.Tables(0).Rows(i).Item("total") =
dstest.Tables(0).Rows(i).Item("price") *
dstest.Tables(0).Rows(i).Item("qty")
Next

Let me know if this helps.........

"Dan Keeley" <ma********@hotmail.com> wrote in message
news:jb****************@newsfep4-winn.server.ntli.net...
Hi,

I have a dataset which is used to populate my datagrid something like this: My question is, how do I add a caluclated display column to the datagrid?
It will be based on ScoreCardScore...

Dim Cmd As OleDbCommand = New OleDbCommand("Select AuditDate,
ScoreCardScore, DetailsScore from Audits where SupplierID = " &
ComboItem.Value.ToString, conn)

' create the data adapter object and pass in the sql command object

myDataAdapter = New System.Data.OleDb.OleDbDataAdapter(Cmd)

' Tell the myDataadabter to fill the dataset

myDataAdapter.Fill(myDataSet, "Name")

dgAudits.DataSource = myDataSet.Tables("Name").DefaultView

Thanks very much for any advice!

Dan

Nov 20 '05 #4
When you bind to the dataset it will be there.

"scorpion53061" <sc****************************@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Untested.......

dstest.Tables(0).Columns.Add("total")
Dim i As Integer
For i = 0 To dstest.Tables(0).Rows.Count - 1
dstest.Tables(0).Rows(i).Item("total") =
dstest.Tables(0).Rows(i).Item("price") *
dstest.Tables(0).Rows(i).Item("qty")
Next

Let me know if this helps.........

"Dan Keeley" <ma********@hotmail.com> wrote in message
news:jb****************@newsfep4-winn.server.ntli.net...
Hi,

I have a dataset which is used to populate my datagrid something like

this:
My question is, how do I add a caluclated display column to the datagrid? It will be based on ScoreCardScore...

Dim Cmd As OleDbCommand = New OleDbCommand("Select AuditDate,
ScoreCardScore, DetailsScore from Audits where SupplierID = " &
ComboItem.Value.ToString, conn)

' create the data adapter object and pass in the sql command object

myDataAdapter = New System.Data.OleDb.OleDbDataAdapter(Cmd)

' Tell the myDataadabter to fill the dataset

myDataAdapter.Fill(myDataSet, "Name")

dgAudits.DataSource = myDataSet.Tables("Name").DefaultView

Thanks very much for any advice!

Dan


Nov 20 '05 #5
Dan
Have you tried something like:

Dim myTable As DataTable = myDataSet.Tables("Name")
Dim myColumn As New DataColumn("Calculated",
GetType(Decimal), "col1 * col2")
myColumn.AutoIncrement = False
myColumn.ReadOnly = True
myTable.Columns.Add(myColumn)

Sample adapted from:
http://msdn.microsoft.com/library/de...ctorTopic4.asp

See the topic for DataColumn.Expression on the expression syntax allowed.

Of course if you are pre-defining your DataSet with an xsd, you can use the
designer to add the calculated column.

Hope this helps
Jay

"Dan Keeley" <ma********@hotmail.com> wrote in message
news:jb****************@newsfep4-winn.server.ntli.net...
Hi,

I have a dataset which is used to populate my datagrid something like this: My question is, how do I add a caluclated display column to the datagrid?
It will be based on ScoreCardScore...

Dim Cmd As OleDbCommand = New OleDbCommand("Select AuditDate,
ScoreCardScore, DetailsScore from Audits where SupplierID = " &
ComboItem.Value.ToString, conn)

' create the data adapter object and pass in the sql command object

myDataAdapter = New System.Data.OleDb.OleDbDataAdapter(Cmd)

' Tell the myDataadabter to fill the dataset

myDataAdapter.Fill(myDataSet, "Name")

dgAudits.DataSource = myDataSet.Tables("Name").DefaultView

Thanks very much for any advice!

Dan

Nov 20 '05 #6
you were right Jay sorry.......

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Dan
Have you tried something like:

Dim myTable As DataTable = myDataSet.Tables("Name")
Dim myColumn As New DataColumn("Calculated",
GetType(Decimal), "col1 * col2")
myColumn.AutoIncrement = False
myColumn.ReadOnly = True
myTable.Columns.Add(myColumn)

Sample adapted from:
http://msdn.microsoft.com/library/de...ctorTopic4.asp
See the topic for DataColumn.Expression on the expression syntax allowed.

Of course if you are pre-defining your DataSet with an xsd, you can use the designer to add the calculated column.

Hope this helps
Jay

"Dan Keeley" <ma********@hotmail.com> wrote in message
news:jb****************@newsfep4-winn.server.ntli.net...
Hi,

I have a dataset which is used to populate my datagrid something like

this:
My question is, how do I add a caluclated display column to the datagrid? It will be based on ScoreCardScore...

Dim Cmd As OleDbCommand = New OleDbCommand("Select AuditDate,
ScoreCardScore, DetailsScore from Audits where SupplierID = " &
ComboItem.Value.ToString, conn)

' create the data adapter object and pass in the sql command object

myDataAdapter = New System.Data.OleDb.OleDbDataAdapter(Cmd)

' Tell the myDataadabter to fill the dataset

myDataAdapter.Fill(myDataSet, "Name")

dgAudits.DataSource = myDataSet.Tables("Name").DefaultView

Thanks very much for any advice!

Dan


Nov 20 '05 #7
excellent thats perfect!

I managed to do exactly what i wanted with an expression field

Cheers!
Dan
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Dan
Have you tried something like:

Dim myTable As DataTable = myDataSet.Tables("Name")
Dim myColumn As New DataColumn("Calculated",
GetType(Decimal), "col1 * col2")
myColumn.AutoIncrement = False
myColumn.ReadOnly = True
myTable.Columns.Add(myColumn)

Sample adapted from:
http://msdn.microsoft.com/library/de...ctorTopic4.asp
See the topic for DataColumn.Expression on the expression syntax allowed.

Of course if you are pre-defining your DataSet with an xsd, you can use the designer to add the calculated column.

Hope this helps
Jay

"Dan Keeley" <ma********@hotmail.com> wrote in message
news:jb****************@newsfep4-winn.server.ntli.net...
Hi,

I have a dataset which is used to populate my datagrid something like

this:
My question is, how do I add a caluclated display column to the datagrid? It will be based on ScoreCardScore...

Dim Cmd As OleDbCommand = New OleDbCommand("Select AuditDate,
ScoreCardScore, DetailsScore from Audits where SupplierID = " &
ComboItem.Value.ToString, conn)

' create the data adapter object and pass in the sql command object

myDataAdapter = New System.Data.OleDb.OleDbDataAdapter(Cmd)

' Tell the myDataadabter to fill the dataset

myDataAdapter.Fill(myDataSet, "Name")

dgAudits.DataSource = myDataSet.Tables("Name").DefaultView

Thanks very much for any advice!

Dan


Nov 20 '05 #8
scorpion53061,
Don't be sorry, as sometimes you need to use the loop you demonstrated!

For example the expression you are attempting to calculate is too complex
for the ADO.NET expression syntax. (interest & financial calculations or
other custom functions).

Or you want to have explicit control over when the column is recalculated,
not have it recalculate automatically.

Note I can see using either the loop or the DataTable.ColumnChanging event
to handle complex expressions. If I was displaying the values in a Windows
Grid, I would probably use the event as the grid would then be updated as I
changed items. In ASP.NET or non-visual windows grids I would probably use
the loop...

For explicit control over when the recalculation occurs, the loop makes more
sense to me.

Hope this helps
Jay

"scorpion53061" <sc****************************@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
you were right Jay sorry.......

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Dan
Have you tried something like:

Dim myTable As DataTable = myDataSet.Tables("Name")
Dim myColumn As New DataColumn("Calculated",
GetType(Decimal), "col1 * col2")
myColumn.AutoIncrement = False
myColumn.ReadOnly = True
myTable.Columns.Add(myColumn)

Sample adapted from:

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

See the topic for DataColumn.Expression on the expression syntax allowed.

Of course if you are pre-defining your DataSet with an xsd, you can use

the
designer to add the calculated column.

Hope this helps
Jay

"Dan Keeley" <ma********@hotmail.com> wrote in message
news:jb****************@newsfep4-winn.server.ntli.net...
Hi,

I have a dataset which is used to populate my datagrid something like

this:
My question is, how do I add a caluclated display column to the

datagrid? It will be based on ScoreCardScore...

Dim Cmd As OleDbCommand = New OleDbCommand("Select AuditDate,
ScoreCardScore, DetailsScore from Audits where SupplierID = " &
ComboItem.Value.ToString, conn)

' create the data adapter object and pass in the sql command object

myDataAdapter = New System.Data.OleDb.OleDbDataAdapter(Cmd)

' Tell the myDataadabter to fill the dataset

myDataAdapter.Fill(myDataSet, "Name")

dgAudits.DataSource = myDataSet.Tables("Name").DefaultView

Thanks very much for any advice!

Dan



Nov 20 '05 #9

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

Similar topics

2
2211
by: Mark Kola | last post by:
I have ran into an interesting situation. I have a calculated field based on a combobox column that somtimes is not requerying when I change the combo box value. Combobox cboCustomer 2...
0
974
by: Rythm Music | last post by:
I have seen examples and samples such that you can show the Related Tables Data in the current Table. The syntax is something like: ' add a new calculated column to the Categories table, with...
1
1296
by: Sean | last post by:
I have a table I am using to load a DataSet.DataTable to display data on a DataGrid. I have a Column called StartTime that is a DateTime and I have a column called Duration that is an Int32, that...
0
1779
by: Manish | last post by:
Hey Guys I am using a datagrid to extract information out of SQL Server datbase. The fields extracted are category,week,budget,Last Year,Forecast and Projection. Also i add a calculated column...
1
1915
by: Manish | last post by:
Hello Everyone I am having weird problem in my datagrid bounded to datatable. My datatable is populated from SQLServer database. DataGrid has Calculated column Week% and Calculated record, SPLH....
0
1272
by: ad | last post by:
I used the new TableAdapter feature of VS2005. I want to create a complex calculated column when I desgin a DataTable in a typed dataset. The defined function like convert, len, isnull... in not...
2
7975
by: markm75c | last post by:
Does anyone know of a way to sort a column which isnt databound or an actual field in the database, but is derived from a method? IE. I have a grid showing stats for softball, with a calculated...
1
1766
by: Robert Bravery | last post by:
HI All, I am looking for a way to create some calculated columns in my typed dataset (VS 2005). This must be based on a datetime column in an SQL2005 table. The calculated column should return...
2
4816
by: SammyBar | last post by:
Hi, I'm trying to display a DataSet data by using a GridView control on Visual Studio 2005 professional. I'm displaying the DataSet directly, without using the DataSource object. I can display...
0
7064
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
7261
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,...
0
7315
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...
1
6974
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...
0
7445
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
5559
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,...
0
3158
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...
0
3147
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
369
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...

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.