Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET2.0 .NET3.0 C#3.0 C# ASP , +
I want to generate columns in a grid dynamically, i used grid.addcolumn property but
My code is throwing error like "Column name already exists". The error is because the procedure which am using
in database returning same values. I can't use 'distinct' in my procedure because the procedure returning more than one field and only
the field which i need to show as a dynamic column is repeating.
So i need to do one filtering in ASP.net code.
Please please help me to select the distinct fields from the procedure output set.
Posted 4-Mar-13 2:41am
Kavitha_b1.4K
Edited 4-Mar-13 3:42am
v2
Comments
willington.d at 4-Mar-13 7:47am
   
Could you please post the code? So that we can understand more.
vishal.shimpi at 4-Mar-13 8:35am
   
what u want to do? u are retrieving row values from database and creating the column of that name..
Kavitha le at 4-Mar-13 8:41am
   
Am not suppose to post the code because of some security reasons.
Here i need to add columns in a grid dynamically.Column names we are fetching using one procedure.But that procedure returning duplicate values so am getting error while adding same columns.
So i need to filter the data retrieved by the procedure. I need distinct values.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

i think , it will help you
 
public DataTable SelectDistinct(DataTable SourceTable, string FieldName)
{
    // Create a Datatable  datatype same as FieldName
    DataTable dt = new DataTable(SourceTable.TableName);
    dt.Columns.Add(FieldName, SourceTable.Columns[FieldName].DataType);
    // Loop each row & compare each value with one another
    // Add it to datatable if the values are mismatch
    object LastValue = null;
    foreach (DataRow dr in SourceTable.Select("", FieldName))
    {
        if (LastValue == null || !(ColumnEqual(LastValue,dr[FieldName])))
        {
            LastValue = dr[FieldName];
           dt.Rows.Add(new object[] { LastValue });
        }
    }
    return dt;
}
  Permalink  
v2
Comments
Kavitha le at 4-Mar-13 9:39am
   
Not working
Kavitha le at 4-Mar-13 9:39am
   
Please help me......:(
 
Kavitha

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 299
1 Maciej Los 295
2 Sergey Alexandrovich Kryukov 230
3 Aajmot Sk 191
4 Sinisa Hajnal 166
0 OriginalGriff 7,760
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,785


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 4 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100