Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a datatable it contains 3 rows and i want to query for one value

<pre lang="c#">DataView dv=new DataView(_dtrecomendationData);
 if (dv.RowFilter=="Priority=2")
                    {
                        _dtrecomendationData.Rows[0][0] = "--";
                    }


The problem is even though priority value is 2 it is not working.
Posted
Updated 13-Jul-14 23:50pm
v2
Comments
ashok rathod 14-Jul-14 5:54am    
what is type of priority column ?
chandra sekhar 14-Jul-14 5:56am    
Integer
ashok rathod 14-Jul-14 5:57am    
try out

dv.RowFilter-"Priority='2'"
ashok rathod 14-Jul-14 6:07am    
here dv.RowFilter will not return boolean type so it wont get into if loop. can you check is it going into if loop and second thing here is that as u had taken two things DataView and datatable so they both will work as differently. So Try out (dv.DefaultView as DataTable).Rows[0][0] does it making any difference ?

use following code


C#
DataView dv=new DataView(_dtrecomendationData);
 dv.RowFilter = "Priority = 2";
 if (dv.ToTable().Rows.Count > 0)
       {
            _dtrecomendationData.Rows[0][0] = "--";
        }
 
Share this answer
 
v2
Comments
chandra sekhar 14-Jul-14 6:18am    
Edit the post i am unable to see dv.Rowfilter==??
PrakashCs.net 14-Jul-14 6:26am    
if you want to update same row which is filter use following code

if (_dtrecomendationData.Select("Priority = 2").Length > 0)
{
DataRow[] dr = _dtrecomendationData.Select("Priority = 2");

foreach (DataRow dre in dr)
{
dre["Priority"] = "--";
}

_dtrecomendationData.AcceptChanges();
}
chandra sekhar 14-Jul-14 6:27am    
But what if i have more rows with the priority=2?? I have to makes them as --
PrakashCs.net 14-Jul-14 6:36am    
use this solution

if you want to update same row which is filter use following code

if (_dtrecomendationData.Select("Priority = 2").Length > 0)
{
DataRow[] dr = _dtrecomendationData.Select("Priority = 2");

foreach (DataRow dre in dr)
{
dre["Priority"] = "--";
}

_dtrecomendationData.AcceptChanges();
}
you can try like this
Filtered value requires 'value' pattern

dataView.RowFilter = "Price = '1199.90'" 


http://www.csharp-examples.net/dataview-rowfilter/[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900