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

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 2184
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
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
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
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
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
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
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
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
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
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
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:
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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.