Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / General / October 2004

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Terry - 29 Oct 2004 17:54 GMT
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();
W.G. Ryan eMVP - 29 Oct 2004 23:38 GMT
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.

Signature

W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.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
[quoted text clipped - 49 lines]
> dgSummary.TableStyles.Add(tsl);
> this.sqlConnection1.Close();

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.