How Group By And Sum Values In DataTable

Jun 19, 2010

How group by and sum values in DataTable??I have a DataTable that looks like this:Id Value1 4.01 5.03 1.02 2.03 3.0I want to end up with (probably a new DataTable) that contains the sum ofvalues grouped by Id like this:Id SumOfValue1 9.02 2.03 4.

View 10 Replies


Similar Messages:

C# - Select DataTable (only Some Values) From _GetDisplayData And GROUP Data By Days Where Group Rules Is Different For Different Columns

Mar 4, 2010

Stack-Overflow :3 I've got a kind of hard-case question.

So I'll try clearly explain my idea with my poor english :/ need select to DataTable SOME values from ???_**GetDisplayData **procedure for each day of previos month (GROUP IT) where group rules for different columns is different


I need to select some values in stored procedure from other stored procedure like this :

SELECT X FROM Y_Procedure(@ProcedureParameters)Also I need to select from dynamic SQL Procedure like

Y_Procedure=@Y+'_Procedure'
SELECT X FROM Y_Procedure(@ProcedureParameters)


Also I need to load it to DataTable :-/INSERT INTO @Report (CellHorizontal, CellVertical, CellValue) --to TABLE
SELECT Date,X2,X3 FROM Y_GetDisplayData(@Param)

SET NOCOUNT OFF;
SELECT *
FROM @Report

GetDisplayData works as select with parameters and that doesn't returns SQL DataTable
And there is no way to recode GetDisplayData's procedures, it's just constant procedures for me.Finally I need to Group nodes from this table

INSERT INTO @Report (CellHorizontal, CellVertical, CellValue)
SELECT T1.Date,
IF ((Select grouptype...)=1) T1.X2 + T2.X2
ELSE IF ((Select grouptype...)=2) AVG(T1.X2,T2.X2),
IF ((Select grouptype...)=1) T1.X3 + T2.X3
ELSE IF ((Select grouptype...)=2) AVG(T1.X3,T2.X3),
(SELECT T2.Date,X2,X3 FROM Y_GetDisplayData(@Param) T2
WHERE T2.Date>T1.Date AND T2.Date>=T1.Date)
FROM Y_GetDisplayData(@Param) T1
GROUP BY EVERY DAY ???--and here is epic fail


I can make all stuff on asp server :And C# allows me to use something like SelectCommand = IzmProc + "_GetDisplayData"; And then I will work (select special data) with DataTables on ASP.NET Server but it's better to make all on SQL ... But looking like it's just unrealizable on SQL >_<

I gonna think about C# realization,but my code is very weird , got errors and doesn't works >_<

public static DataTable GetReport(string Param)
{
System.Configuration.ConnectionStringSettings connSetting = ConfigurationManager.ConnectionStrings["FlowServerConnectionString"]; [code].....

View 3 Replies

Web Forms :: How To Get Four Values As A Group From Arraylist

Dec 7, 2010

I want to add four values to the arraylist when i click on UP button. and if i click on UP button again i need to add four more values to arraylist.

While getting the values from arraylist i need get four values at a time and so on .

View 1 Replies

Bind TextBox Default Values As A Group?

Jan 20, 2011

I'm making an "Edit Customer" page in asp .net and want to enter in all the current values into the TextBoxes on PageLoad. Is there a way to do this using databinding, or do I have to get the Customer from the DataContext and then set the TextBoxes line-by-line? ie

firstNameTB.Text = Customer.FirstName;
lastNameTB.Text = Customer.LastName;
...

View 2 Replies

Web Forms :: Group (Remove) Duplicate Values From DropDownList

May 7, 2015

I have a master table relationship, i.e. depending on what is selected in the dropdown list the grid show the relevant data.In the database there are several identical entries for the Position field, for instance there are four marketing managers that have different name. How can i group the identical Position name in the dropdown and when selected the grid should display all marketing managers. Here is the code:

<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="sqlDdl"
DataTextField="ID" DataValueField="Postion">
</asp:DropDownList>
<asp:GridView ID="grid" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="sqlCon" EnableModelValidation="True">

[Code] ....

View 1 Replies

Forms Data Controls :: Checkbox Selection Based On Group Column Values In Gridview?

Jul 28, 2010

I have to select checkboxes besed on group column values. If you see below gridview, column 3 (GroupN) has 1,1,1,1,2,2,2,2....etc (this column data is not static, will change based on page index. i.e PageIndex =2 may starts with 7,7,7,8,8,8,8,8,9,9,9 etc).

Now My question is.

1). If user selected '1', we have to store value and user must and should select another '1' (atleast two times).

2) If user selected '1', and user trying select '2'. Giving error says "Must have select one then one record in group to combine' (will not allow) and unselect '2'.

3) If user selected '1' atleast two times, and user trying select '2'. Will allow.

4) If user selected '1' atleast two times and selected '2' one time, trying to select '3'. will not allow user to select '3'.

View 3 Replies

Getting Values From Selected DataTable Row?

Jul 27, 2010

What is the code to get the values of the selected data table row?

I set up the double click event, but I can't find anything that will get the values of the selected row.

private void DataTable1_MouseDoubleClick(object sender, System.Windows.Forms.MouseEventArgs e)
{
DataTable1.Current Row // This doesn't work. What does?
}

View 3 Replies

ADO.NET :: How To Update Values In DataTable

Dec 16, 2010

Sql Table has 2 fields "id" and "name". Also "id" is the primary key with identity. I am using data adapter to fill data table "myTable". This brings id/name pairs form the database and fill "myTable".

[Code]....

Later I add new rows to "myTable".

[Code]....

and call dataadapter.Update(myTable). Dataadapter will add new rows to the database and the database will assign new id to each new ecord. StoredProcedure which actually insert new record, returns @@identity. How can I add this @@identity to myTable

[Code]....

Data Adapter insert new records reursively and each insert in the database causes @@identity to be returned. I want dataadapter to add @@identity to myTable.

View 4 Replies

SQL Server :: Can Get Values From Datatable

Oct 1, 2010

i have number of values in a datatable... I need to insert that datatable values into DataBase. how i can get the values from Datatable and insert values one by one

View 3 Replies

ADO.NET :: Distinct Values From A Column In Datatable?

Sep 21, 2010

I have a datatable dt with 4 columns. I want to retrieve only distinct values from column1 of datatable.

How can I achieve this using c# code?

View 3 Replies

C# - How To Find Null Values In A Datatable

Mar 10, 2011

I have a data table say i have a column like x which is primary key so i should get the row where this x values in empty.

View 2 Replies

Assigning Viewstate Values To A Datatable?

Jan 26, 2011

I have a dataset which consists of a set of records. I have put this dataset records in a viewstate so that I can access it from a different method on the same page.

ds = TelephoneDtl.GetTelephoneData();

ViewState["CurrentPos"] = ds.Tables[2];

I now want this view state values to be assigned to a datatable. Something like this:

datatable dt = ViewState["CurrentPos"];

But doing this gives me a typecast error

View 4 Replies

Adding Values For Datatable Column?

Dec 27, 2010

i have a sum column in my datatable and want to add the values?

is compute a good method to use?

View 1 Replies

DataTable Is Always Returns Empty Values?

Feb 17, 2011

I'm .NET newbie and I have to write function which executes stored procedure and return DataTable.

my SqlConnection is already initialized and while running in debugger I can see DataAdapter returns values, but my DataTable is empty.

public DataTable ExecStoredProcedure(String spName, String uId)
{
DataTable dt = new DataTable();
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(spName, conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UnitIDList", uId);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
}
catch (SqlException ex)
{
throw new Exception(ex.StackTrace + ex.Message);.......

View 1 Replies

ADO.NET :: Store The Datatable Values Into The 1-D Array

Oct 25, 2010

how to store the datatable values into the 1-D array , i know in for loop

View 1 Replies

C# - Check For Existing Values In Datatable?

Dec 17, 2010

if (dt.Rows[i]["Code"] == code)
{
Label lblLang = (Label)(((e.Item as GridItem).FindControl("lblLang") as Label));
lblLang.Visible = true;
}
else
{
}
}

I am adding a new language Fr-FR in the code above. fr-FR already exists in my DB's Language Table. I do not want to add duplicate values in my table. There should be only one fr-FR.

View 2 Replies

Access The Group Of A Linq Group - By Query From A Nested Repeater Control?

Mar 26, 2010

I'm using a linq group by query (with two grouping parameters) and would like to use the resulting data in a nested repeater.

var dateGroups = from row in data.AsEnumerable()
group row by new { StartDate = row["StartDate"], EndDate = row["EndDate"] };
"data" is a DataTable from an SqlDataAdapter-filled DataSet. "dateGroups" is used in the parent repeater, and I can access the group keys using Eval("key.StartDate") and Eval("key.EndDate").

Since dateGroups actually contains all the data rows grouped neatly by Start/End date, I'd like to access those rows to display the data in a child repeater. To what would I set the child repeater's DataSource? I have tried every expression in markup I could think of; I think the problem is that I'm trying to access an anonymous member (and I don't know how.) In case it doesn't turn out to be obvious, what would be the expression to access the elements in each iteration of the child repeater? Is there an expression that would let me set the DataSource in the markup, or will it have to be in the codebehind on some event in the parent repeater?

View 3 Replies

Linq To DataTable Not Producing Distinct Values?

Oct 19, 2010

I have a datatable which has been dynamically generated from FoxPro tables using a UNION Select statement. e.g.

SELECT * FROM x UNION SELECT * FROM y UNION SELECT * FROM Z ORDER By v_alue1

This produces a datatable with about 100 rows, each containing many fields, one of which is c_olor. From this datatable, I would like to select the distinct colors and then output in a dropdown.

I have a public class Color which just has one property which I can then use as the DataTextField and DataValueField for the dropdownlist

[code]...

However this never results in the distinct colors.

I have searched and searched for what I am looking for, and this seems to be one of the methods to produce a distinct set of results, but this and the others do not work.

My reasoning behind getting the colors this way, is that I need to get various other distinct values from the same UNION SELECT datasource, so would just do one DB call, cache the results, and then just used this cached datasource to retrieve all my distinct values.

View 2 Replies

Storing Values In List Rather Than Datatable Session?

Jan 19, 2011

i have a list for my shopping cart which i currently store in my datatable and then store it in a session. to avoid using sessions is it best to create a class where the datatable is stored and can be accessed from anywhere?

View 2 Replies

Web Forms :: Bind DataTable Values To Label?

Jan 24, 2012

I need to display the softwares expired validating it with current date.....

but when i fill the dataset and displaying the data in a label.

suppose i have retrieved 3 softwares but i have already put 10 labels to show first 10 expired softwares

iam getting a error on 4th label as it is empty so wat condition should i mention to overcome this problem...

my sample code----

Dim cmd As SqlCommand = New SqlCommand("select distinct productname from productinfo where expirydate > ='" + localdate + "' ", conn) Dim dalogin As SqlDataAdapter = New SqlDataAdapter(cmd) Dim dtlogin As DataSet = New DataSet() dalogin.Fill(dtlogin) If (dtlogin.Tables(0).Rows.Count > 0) Then lblexpiry1.Text = dtlogin.Tables(0).Rows(0).Item(0) If dtlogin.Tables(0).Rows(1).Item(0) Is Nothing Then td1.InnerHtml = "" Else Label1.Text = dtlogin.Tables(0).Rows(1).Item(0) End If If dtlogin.Tables(0).Rows(2).Item(0) Is Nothing Then td1.InnerHtml = "" Else Label2.Text = dtlogin.Tables(0).Rows(2).Item(0) End If If dtlogin.Tables(0).Rows(3).Item(0) Is Nothing Then td1.InnerHtml = "" Else Label3.Text = dtlogin.Tables(0).Rows(3).Item(0) End If Label4.Text = dtlogin.Tables(0).Rows(4).Item(0) Label5.Text = dtlogin.Tables(0).Rows(5).Item(0) Label6.Text = dtlogin.Tables(0).Rows(6).Item(0) Label7.Text = dtlogin.Tables(0).Rows(7).Item(0) Label8.Text = dtlogin.Tables(0).Rows(8).Item(0) Label9.Text = dtlogin.Tables(0).Rows(9).Item(0) End If

View 1 Replies

C# - Getting DataTable Values From Code Behind To Client Side Using JavaScript

Dec 9, 2010

getting a particular datatable values from the server to the client using javascript.

Ex.In my class which is Countries.aspx.cs I have this somewhere on my code say on the page load.

DataTable dtbCountries = Repository.GetAllCountries;

my dtbCountries now contains this record

ID Country
1 HongKong
2 Japan
3 Korea

In my webform I want to get the values of my dtbCountries using javascript

<script type="text/javascript">
// my code here to get the dtbCountries values
</script>

What should I do? Or what's the best thing to do to expose my dtbCountries in the client.

View 1 Replies

DataSource Controls :: Inserting Datatable Values Into MS SQL Server DB

Feb 7, 2011

I have a 3 column datatable in a session. I know I can use DataAdapter to do the insert but i only need to insert 2 of the columns.

View 3 Replies

Forms Data Controls :: DataTable Values And Rows

May 25, 2010

I have 7 different category pages and although the Cart Page shows selected items From the 1 category , when i select other category page it only shows the selections of first page and not the others.
How can i make the DataTable Draw values from all the pages and display them on the Cart? code in first category

[Code]....

i m trying to put the same in each category but it doesn'twork

View 5 Replies

C# - Putting Datatable Comma Separated Values In A String?

Feb 4, 2011

My datatable consists of a column named "ID". The no. of values in this column varies.Sometimes this Datatable fetches 3 IDs in that ID column, sometimes 2. Now if for example, my datatable has three values as 1,2,3. What I want is to put these three values in a string and separate them by commas as folows:-

string test= "1,2,3";

If Datatable has 2 values, then string should be as follows:-

string test= "1,2";

I did try but in vain.

edit:-

DataTable dt=new DataTable;
dt = obj.GetIDs();
for (int i = 0; i < dt.Rows.Count; i++)
{
string test= "What should be here????";
}
edit 2
foreach(DataRow dr in dt.Rows)
{
string str = str + "," + Convert.ToString(dr("ID"));
}


@Rajeev ::Tried this..it says dr is a variable but used as a method. What's wrong?

View 4 Replies

Data Controls :: Bind DataTable Values To CheckBoxList

Apr 2, 2013

I had a problem in binding the checkbox list. Here I explain I had a database with 3 columns.

ex:

address         name    number

bangalore      seker      987585
mangalore     shankar  658741
bangalore      kanna      589725

Now I have select the bangalore in address,so i may get seker and kanna.

And now i have display in my page as like this to checkbox.

seker                                   

987585                 same kanna sholud be displayed.

that is, the seker should be in label and the number should be in checkbox.

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved