473,513 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't insert a Column in DataGrid which DataSet does not Contain

All I'm doing, is using the Compute Method and getting the Sum of the Amount
field in my SQL Query. The problem is getting the Data Table to add a Column
and put the total in the "Total Column". I can see that I'm getting the data
I want, But can not display it. I could sure use the Help.
Thanks In Advance

THE CODE:
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
this.sqlConnection1.Open();
da.SelectCommand=scmd;
da.Fill(ds,"Global");

DataGridTableStyle tsl = new DataGridTableStyle();
DataGridColumnStyle TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "First";
TextCol.HeaderText = "First";
TextCol.Width = 150;

DataGridColumnStyle COL = new DataGridTextBoxColumn();
COL.MappingName = "Last";
COL.HeaderText = "Last";
COL.Width = 150;
DataGridColumnStyle MI = new DataGridTextBoxColumn();
MI.MappingName = "MI";
MI.HeaderText = "MI";
MI.Width = 25;

DataGridColumnStyle Address = new DataGridTextBoxColumn();
Address.MappingName = "Address";
Address.HeaderText = "Address";
Address.Width = 150;

DataGridColumnStyle Total = new DataGridTextBoxColumn();
Total.MappingName = ds.Tables["Global"].Compute("Sum(Amount)","Amount >
0").ToString();
Total.HeaderText = "Total";
Total.Width = 25;

tsl.MappingName="Global";

tsl.GridColumnStyles.Add(TextCol);
tsl.GridColumnStyles.Add(COL);
tsl.GridColumnStyles.Add(Total);
tsl.GridColumnStyles.Add(MI);
tsl.GridColumnStyles.Add(Address);
tsl.GridColumnStyles.Add(Total);

dgSummary.DataSource=ds;
dgSummary.DataMember="Global";
dgSummary.TableStyles.Add(tsl);
this.sqlConnection1.Close();
Jul 21 '05 #1
1 2194
Where are you adding the DataColumn? If you add the column to the Columns
collection and then just map a COlumnstyle to it, it should show
http://www.knowdotnet.com/articles/expressions.html

However compute works on aggregates so I'm not sure if you want the Total in
each column.

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Terry" <Te***@discussions.microsoft.com> wrote in message
news:8F**********************************@microsof t.com...
All I'm doing, is using the Compute Method and getting the Sum of the Amount field in my SQL Query. The problem is getting the Data Table to add a Column and put the total in the "Total Column". I can see that I'm getting the data I want, But can not display it. I could sure use the Help.
Thanks In Advance

THE CODE:
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
this.sqlConnection1.Open();
da.SelectCommand=scmd;
da.Fill(ds,"Global");

DataGridTableStyle tsl = new DataGridTableStyle();
DataGridColumnStyle TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "First";
TextCol.HeaderText = "First";
TextCol.Width = 150;

DataGridColumnStyle COL = new DataGridTextBoxColumn();
COL.MappingName = "Last";
COL.HeaderText = "Last";
COL.Width = 150;
DataGridColumnStyle MI = new DataGridTextBoxColumn();
MI.MappingName = "MI";
MI.HeaderText = "MI";
MI.Width = 25;

DataGridColumnStyle Address = new DataGridTextBoxColumn();
Address.MappingName = "Address";
Address.HeaderText = "Address";
Address.Width = 150;

DataGridColumnStyle Total = new DataGridTextBoxColumn();
Total.MappingName = ds.Tables["Global"].Compute("Sum(Amount)","Amount >
0").ToString();
Total.HeaderText = "Total";
Total.Width = 25;

tsl.MappingName="Global";

tsl.GridColumnStyles.Add(TextCol);
tsl.GridColumnStyles.Add(COL);
tsl.GridColumnStyles.Add(Total);
tsl.GridColumnStyles.Add(MI);
tsl.GridColumnStyles.Add(Address);
tsl.GridColumnStyles.Add(Total);

dgSummary.DataSource=ds;
dgSummary.DataMember="Global";
dgSummary.TableStyles.Add(tsl);
this.sqlConnection1.Close();

Jul 21 '05 #2

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

Similar topics

2
447
by: John Latten | last post by:
Hi there, I have got a problem when adding extra (= dummy) columns to a datagrid. I have a datagrid that is bound to a datatable. The datatable is filled with data from a SQL Server 2000...
2
1415
by: PaulNaude | last post by:
VB.NET 2003 I am battling with a specific procedure that does not allow me to update my data adapter due to an apparent syntax error. I created the data adapter usign the drag and drop method...
10
3059
by: Robert Schuldenfrei | last post by:
Hi NG: I have the following code working. The GetProdStrtList() returns a DataTable called psTable. A Grid control is successfully bound to this table and displays correctly. I would like to...
0
10840
by: a | last post by:
I've read and split a delimited text file into a dataset. It looks fine in a datagrid (5 columns and 5,000 rows), but I've been trying, without success, to then insert the resulting dataset called...
6
5050
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
0
1756
by: Jim Hammond | last post by:
The code below implements two datagrid columns that display images. The first column is just a test that always displays the same image directly from a file. The second column pulls the image from...
1
1444
by: louise raisbeck | last post by:
This sounds complicated but bear with me. I have a datagrid. It is dynamic in that, i dont know how many columns i will have until the dataset is back so i have to build the datagrid dynamically. I...
1
219
by: Terry | last post by:
All I'm doing, is using the Compute Method and getting the Sum of the Amount field in my SQL Query. The problem is getting the Data Table to add a Column and put the total in the "Total Column". I...
6
2930
by: insirawali | last post by:
Hi all, I have this problem, i need to know is there a way i cn use the data adapter's update method in this scenario. i have 3 tables as below create table table1{ id1 int identity(1,1)...
0
7265
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
7388
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
7545
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
7111
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...
1
5095
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3240
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
3228
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1605
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 ...
0
461
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.