views:

126

answers:

4

in my db i have values as True/False/false/true.... i need to get oly the Distinct Values as True and False and not the all values as True & False & false & true...

my code:

 DataTable dv= dt.DefaultView.ToTable(true, col.header);

dv.Casesensitive=true;

but i got the values as True & False & false.

how to avoid both similar values even if they as caps / small letters and to get oly True & False values.

it should be done oly at the backend. in C# not through query......

A: 

Try setting the case of the values when selecting. Some thing like SELECT ... upper(bool_column_name) ... FROM ...

Also, check this out.

thelost
+1  A: 

Or, you could just return a distinct list (assuming case insensitive db collation):

SELECT DISTINCT YourField FROM YourTable
AdaTheDev
A nice way of doing it but the original poster said that he had to do it in code, not in the query.
Chris
@Chris - they didn't originally say that...that was a later edit :)
AdaTheDev
@AdaTheDev: Damn edits... ;-)
Chris
A: 

With LINQ you can do something like this:

var s = (from p in dv
             orderby p.YourColumn
             select p.YourColumn.ToUpper()).Distinct();

Here is a good blog post for you.

David Robbins
A: 

Case sensitivity affects search results, it does not affect how items are displayed.

You need to convert the values to upper case, either in the SQL statement that you use to get the data, your view or in code.

Shiraz Bhaiji