Web Forms :: How To Check Distinct Val In Datatable
Jan 28, 2010how can i check distinct val in col_1 of datatable and assign seq no to each distinct val of col_1 to col_2?
View 6 Replieshow can i check distinct val in col_1 of datatable and assign seq no to each distinct val of col_1 to col_2?
View 6 RepliesI am using C# + VSTS 2008 + .Net + ASP.Net + IIS 7.0 + ADO.Net + SQL Server 2008. I have a ADO.Net datatable object, and I want to filter out duplicate/similar records (in my specific rule to judge whether records are duplicate/similar -- if record/row has the same value for a string column, I will treat them as duplicate/similar records), and only keep one of such duplicate/similar records.
The output needs to be a datatable, may output the same datatable object if filter operation could be operated on the same datatable object.
What is the most efficient solution?
I would like to get the distinct value form DataTabel using LINQ.
For example my sample table,
[code]....
1. How to get the distinct Country from Country you like column and the return records as Array or DataTable? (I want only India,USA,UK,Germany )
Is there any way to filter the record values using LINQ?
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?
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.
I have an already created DataTable object which i am using for my girdview (asp.net) i also need to bind a column of that object to a DropDownList. The datatable has the correct details in the column but the column contains more that 1 of the same name in the column - hence I would love to just do some kind of SELECT DISTINCT on the datatable and copy it to a new datatable for use with binding the dropdown.
This would allow me to save resources by making another trip to the database.
Here is an example, the current datatable has a column called items and in this column has the following entries
1
1
1
1
5
5
6
And of course i need only unique items for binding to my dropdown, hence i need the following data
1
5
6
Of course i don't want to change the original datatable object but rather make a copy of it will the new details.
I have the following table structure:
[code]....
The following query returns the default recordset:
[code]....
I would like to select a distinct query based on three fields and display the rest of the fields. For example,
I have firstname, lastname, address, city, state and zip, but I only want to use the distinct on these fields first and last name. However when i use the distinct function I get a distinct on all the selected rows. I just want to distinct firstname and lastname and display the other fields. for example,
Mary Smith New York
Mary Smithy New York
Mary Smith Maine
I would like the result to be:
Mary Smith New York
Mary Smithy New York
I don't care about Mary Smith Maine, because i am only using the distinct for "Mary Smith" firstname and last name and showing the city.
I have gridview wich bind with dynamic datatable.
<asp:GridView ID="grdCountries" runat="server" AutoGenerateColumns="False" ShowHeader="False" OnRowDeleting="grdCountries_RowDeleting" DataKeyNames="country_id" BorderStyle="None" GridLines="None">
i have two datatable, while adding rows in second datatable, i want to first check whether the id in the second datatable matches as in the first datatable, if not only then it should be added in the second datatable, else it should display a message...
i dont have any Primary Key defined on any column, so the rows could be repeatative.
Im using "string user = Database.GetMostRecentReply(id).Rows[0][2].ToString();" to get the username from the most recent reply in my forum.
But how do I check if the row is empty? Im using a try catch at the moment, but there must be a better way to do this.
I am using Compute for summing up a datatable which has a condition. Sometimes, there are no rows inside the datatable matching my criteria so I get an exception on ComputeObject cannot be cast from DBNull to other types.Is there a way to check/filter the datatable to see if it has the desired rows, if yes only then I apply Compute.
total = Convert.ToDecimal(CompTab.Compute("SUM(Share)", "IsRep=0"));
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.
DataSet ds = new DataSet();
string qry = "select Name,Section,present from presentdays where id='" + TextBox1.Text;
qry += "'";
ds=mvl.GETDS(qry);
foreach (DataRow dr in ds.Tables[0].Rows)
{
TextBox2.Text = dr["present"].ToString();
TextBox12.Text=dr["Name"].ToString();
TextBox13.Text=dr["Section"].ToString();
}
there is no data in id='1'i need to throw the error as there is nothing is found in id='1'
check if variable exists in dataset ?
View 1 Repliesmy requirement is to update a duplicate record in datatable.in my website if anyone select a product more than one time then i have to check and update the quantity of that record.i use for loop for this but it is not working properly, it is running perfectly for one product but when i add another product it won't work.how can i do this?Here is my code part which is run on add button click
if (sc.dtcart.Rows.Count > 0)
{
for(int i=0;i<sc.dtcart.Rows.Count;i++)
[code]...
I have one problem with my shopping cart that I really can't figure out all by myself.I want, if a item already exist in the datatable, the quantity to be updated for that item with the new number instead of creating the same item again.I have done a foreach loop because I think that is where I should start.Notes: MyRow[3] is the column holding the quantity.Code:
[Code]....
//Bengt
I have one table(tableName is getDetails and having three column ID, Name, City)
View 6 Replies'DataTable' is an ambiguous reference between 'System.Data.DataTable' and 'Microsoft.Office.Interop.Word.DataTable'
View 3 Replieshow to distinct arraylist value using c#?
View 10 RepliesIf I am passed a datatable and I cant change the column structure..is there anyway to set an existing column to a Primary key so I can easily Find() the row I am looking for?
View 1 Repliesi'm binding data to ddl from database.i'm selecting one column from database table to bind.In that column there may be items with same name.but when selecting in ddl there must be no same values.
View 4 RepliesThis is my last thread [URL] ....
This sp show duplicate row yet, what can i do?
I'm trying to bind a dataset (where the data is coming from a webservice) to a dropdownlist; the problem is that I'm getting duplicates in the list... how can I display distinct values only:
[Code]....
i have table that trace views of my page. every row has the id, date view (dd/mm/yyyy hh/mm/ss) how can i distinct the data into gridview (or something else) and display only the days (01/03/2011, 02/03/2001, 03/03/2011) and to sum the numbers of views (01/03/2011 1,290 views, 02/03/2011 867 views.....)
View 7 Replies