DataView.RowFilter problem

  • Thread starter Thread starter Dave Hagerich
  • Start date Start date
D

Dave Hagerich

I'm using a DataGrid with a DataSet and I'm trying to filter the data being
displayed, using the following code as a test:

DataView theView = new DataView(theDataSet.Tables["Access Viewer"]);
theView.RowFilter = "'Record ID' = '0'";
theView.RowStateFilter = DataViewRowState.ModifiedCurrent;
Debug.WriteLine(string.Format("RowFilter = {0}", theView.RowFilter));
RecordDataGrid.DataSource = theView;
RecordDataGrid.DataBind();

without the RowFilter set all the data comes up but with the RowFilter set I
get nothing. There is a column called Record ID and there are multiple
entries with an ID of 0. Any help would be appreciated.

Thanks,
Dave
 
Your second line of code is wrong I think.
instead of
theView.RowFilter="'RecordID'='0'";
you can type
theView.RowFilter="RecordID=" + 0;
I think that should work. The zero looks like an int and should not be
represented as a string.

Sam-
 
I tried that and during execution I get an exception saying it cant compare
System.Int32 with System.String
Also the name is 'Record ID' because the Column name has a space in it.

Sam Samnah said:
Your second line of code is wrong I think.
instead of
theView.RowFilter="'RecordID'='0'";
you can type
theView.RowFilter="RecordID=" + 0;
I think that should work. The zero looks like an int and should not be
represented as a string.

Sam-
Dave Hagerich said:
I'm using a DataGrid with a DataSet and I'm trying to filter the data
being
displayed, using the following code as a test:

DataView theView = new DataView(theDataSet.Tables["Access Viewer"]);
theView.RowFilter = "'Record ID' = '0'";
theView.RowStateFilter = DataViewRowState.ModifiedCurrent;
Debug.WriteLine(string.Format("RowFilter = {0}", theView.RowFilter));
RecordDataGrid.DataSource = theView;
RecordDataGrid.DataBind();

without the RowFilter set all the data comes up but with the RowFilter set
I
get nothing. There is a column called Record ID and there are multiple
entries with an ID of 0. Any help would be appreciated.

Thanks,
Dave
 
Maybe try theView.RowFilter="Record ID=0"
You might want to remove spaces from column names. I'm not sure but I think
some queries get confused with white space in column names. I'm not sure
though.


Dave Hagerich said:
I tried that and during execution I get an exception saying it cant compare
System.Int32 with System.String
Also the name is 'Record ID' because the Column name has a space in it.

Sam Samnah said:
Your second line of code is wrong I think.
instead of
theView.RowFilter="'RecordID'='0'";
you can type
theView.RowFilter="RecordID=" + 0;
I think that should work. The zero looks like an int and should not be
represented as a string.

Sam-
Dave Hagerich said:
I'm using a DataGrid with a DataSet and I'm trying to filter the data
being
displayed, using the following code as a test:

DataView theView = new DataView(theDataSet.Tables["Access Viewer"]);
theView.RowFilter = "'Record ID' = '0'";
theView.RowStateFilter = DataViewRowState.ModifiedCurrent;
Debug.WriteLine(string.Format("RowFilter = {0}", theView.RowFilter));
RecordDataGrid.DataSource = theView;
RecordDataGrid.DataBind();

without the RowFilter set all the data comes up but with the RowFilter set
I
get nothing. There is a column called Record ID and there are multiple
entries with an ID of 0. Any help would be appreciated.

Thanks,
Dave
 
Ok I removed the space and used
theView.RowFilter="RecordID=0";
and still get nothing

Sam Samnah said:
Maybe try theView.RowFilter="Record ID=0"
You might want to remove spaces from column names. I'm not sure but I think
some queries get confused with white space in column names. I'm not sure
though.


Dave Hagerich said:
I tried that and during execution I get an exception saying it cant compare
System.Int32 with System.String
Also the name is 'Record ID' because the Column name has a space in it.

Sam Samnah said:
Your second line of code is wrong I think.
instead of
theView.RowFilter="'RecordID'='0'";
you can type
theView.RowFilter="RecordID=" + 0;
I think that should work. The zero looks like an int and should not be
represented as a string.

Sam-
I'm using a DataGrid with a DataSet and I'm trying to filter the data
being
displayed, using the following code as a test:

DataView theView = new DataView(theDataSet.Tables["Access Viewer"]);
theView.RowFilter = "'Record ID' = '0'";
theView.RowStateFilter = DataViewRowState.ModifiedCurrent;
Debug.WriteLine(string.Format("RowFilter = {0}", theView.RowFilter));
RecordDataGrid.DataSource = theView;
RecordDataGrid.DataBind();

without the RowFilter set all the data comes up but with the
RowFilter
set
I
get nothing. There is a column called Record ID and there are multiple
entries with an ID of 0. Any help would be appreciated.

Thanks,
Dave
 
Well the syntax looks correct. Maybe the problem is with your dataview
object. You set the table to the "Access Viewer" table maybe there is a
problem with your command string. You might want to paste all the data
processing information.
Dave Hagerich said:
Ok I removed the space and used
theView.RowFilter="RecordID=0";
and still get nothing

Sam Samnah said:
Maybe try theView.RowFilter="Record ID=0"
You might want to remove spaces from column names. I'm not sure but I think
some queries get confused with white space in column names. I'm not sure
though.


Dave Hagerich said:
I tried that and during execution I get an exception saying it cant compare
System.Int32 with System.String
Also the name is 'Record ID' because the Column name has a space in it.

Your second line of code is wrong I think.
instead of
theView.RowFilter="'RecordID'='0'";
you can type
theView.RowFilter="RecordID=" + 0;
I think that should work. The zero looks like an int and should not
be
represented as a string.

Sam-
I'm using a DataGrid with a DataSet and I'm trying to filter the
data
being
displayed, using the following code as a test:

DataView theView = new DataView(theDataSet.Tables["Access Viewer"]);
theView.RowFilter = "'Record ID' = '0'";
theView.RowStateFilter = DataViewRowState.ModifiedCurrent;
Debug.WriteLine(string.Format("RowFilter = {0}",
theView.RowFilter));
RecordDataGrid.DataSource = theView;
RecordDataGrid.DataBind();

without the RowFilter set all the data comes up but with the RowFilter
set
I
get nothing. There is a column called Record ID and there are multiple
entries with an ID of 0. Any help would be appreciated.

Thanks,
Dave
 
I just noticed that you set the RowStateFilter to ModifiedCurrent. You set
the table to DefaultView when you instanced the DataView Object "DataView
theView=new DataView(theDataSet.Tables["Access Viewer"]);"
Is there a reason you set the RowStateFilter to ModifiedCurrent?

Dave Hagerich said:
Ok I removed the space and used
theView.RowFilter="RecordID=0";
and still get nothing

Sam Samnah said:
Maybe try theView.RowFilter="Record ID=0"
You might want to remove spaces from column names. I'm not sure but I think
some queries get confused with white space in column names. I'm not sure
though.


Dave Hagerich said:
I tried that and during execution I get an exception saying it cant compare
System.Int32 with System.String
Also the name is 'Record ID' because the Column name has a space in it.

Your second line of code is wrong I think.
instead of
theView.RowFilter="'RecordID'='0'";
you can type
theView.RowFilter="RecordID=" + 0;
I think that should work. The zero looks like an int and should not
be
represented as a string.

Sam-
I'm using a DataGrid with a DataSet and I'm trying to filter the
data
being
displayed, using the following code as a test:

DataView theView = new DataView(theDataSet.Tables["Access Viewer"]);
theView.RowFilter = "'Record ID' = '0'";
theView.RowStateFilter = DataViewRowState.ModifiedCurrent;
Debug.WriteLine(string.Format("RowFilter = {0}",
theView.RowFilter));
RecordDataGrid.DataSource = theView;
RecordDataGrid.DataBind();

without the RowFilter set all the data comes up but with the RowFilter
set
I
get nothing. There is a column called Record ID and there are multiple
entries with an ID of 0. Any help would be appreciated.

Thanks,
Dave
 
Ok, this is the function that is called to display the table it is called
from a button in each DataRow

private void RecordDataGrid_ItemCommand(object source,
DataGridCommandEventArgs e)
{
if(e.CommandName == "Show Access Viewer")
{
//adjust the recorddatagrid columns
RecordDataGrid.Columns.Clear();

BoundColumn DateColumn = new BoundColumn();
DateColumn.DataField = "Date";
DateColumn.HeaderText = "Date";
DateColumn.ReadOnly = true;

BoundColumn UserColumn = new BoundColumn();
UserColumn.DataField = "Username";
UserColumn.HeaderText = "Username";
UserColumn.ReadOnly = true;

BoundColumn FieldColumn = new BoundColumn();
FieldColumn.DataField = "Field";
FieldColumn.HeaderText = "Field";
FieldColumn.ReadOnly = true;

BoundColumn PreviousValueColumn = new BoundColumn();
PreviousValueColumn.DataField = "Previous Value";
PreviousValueColumn.HeaderText = "Previous Value";
PreviousValueColumn.ReadOnly = true;

BoundColumn NewValueColumn = new BoundColumn();
NewValueColumn.DataField = "New Value";
NewValueColumn.HeaderText = "New Value";
NewValueColumn.ReadOnly = true;

BoundColumn RecordIDColumn = new BoundColumn();
RecordIDColumn.DataField = "RecordID";
RecordIDColumn.HeaderText = "Record ID";
RecordIDColumn.ReadOnly = true;

RecordDataGrid.Columns.Add(RecordIDColumn);
RecordDataGrid.Columns.Add(DateColumn);
RecordDataGrid.Columns.Add(UserColumn);
RecordDataGrid.Columns.Add(FieldColumn);
RecordDataGrid.Columns.Add(PreviousValueColumn);
RecordDataGrid.Columns.Add(NewValueColumn);

DataView theView = new DataView(theDataSet.Tables["Access Viewer"]);
theView.RowFilter = "RecordID=0";
theView.RowStateFilter = DataViewRowState.ModifiedCurrent;
Debug.WriteLine(string.Format("RowFilter = {0}",
theView.RowFilter));
RecordDataGrid.DataSource = theView;
RecordDataGrid.DataBind();
}
}

this is the function that sets the table up it is called everytime the page
goes through the lifecycle

private void addDataSource(Records recordSet, Job theJob)
{
//make sure any old data source is removed
RecordDataGrid.DataSource = null;
//clear the columns
RecordDataGrid.Columns.Clear();
//add the columns to the Record Data Grid
setRecordGridColumns(recordSet);

if(Session["TheDataSet"] == null)
{
theDataSet = new DataSet(theJob.theJobName);
//create the records table
DataTable theTable = new DataTable("Records");
//the gridstyle
//DataGridTableStyle theGridStyle = new DataGridTableStyle();
//theGridStyle.MappingName = "Records";
//add the id column
DataColumn theRecordsIDColumn = new DataColumn("RecordID",
typeof(int));
theRecordsIDColumn.ReadOnly = true;
theTable.Columns.Add(theRecordsIDColumn);

//loop through the fields and add a new column for each
foreach(Field theField in recordSet.theFields)
{
DataColumn newColumn = new DataColumn();
newColumn.ColumnName = theField.theName;
newColumn.Unique = false;
newColumn.ReadOnly = false;
newColumn.DataType = System.Type.GetType("System.String");
theTable.Columns.Add(newColumn);
}

//recordDataGrid.TableStyles.Add(theGridStyle);
//create the access viewer table
DataTable theAccessViewerTable = new DataTable("Access Viewer");
//create the columns
DataColumn dateColumn = new DataColumn("Date", typeof(DateTime));
dateColumn.ReadOnly = true;
DataColumn userColumn = new DataColumn("Username", typeof(string));
userColumn.ReadOnly = true;
DataColumn fieldColumn = new DataColumn("Field", typeof(string));
fieldColumn.ReadOnly = true;
DataColumn previousValueColumn = new DataColumn("Previous Value",
typeof(string));
previousValueColumn.ReadOnly = true;
DataColumn newValueColumn = new DataColumn("New Value",
typeof(string));
newValueColumn.ReadOnly = true;
DataColumn recordID = new DataColumn("RecordID", typeof(int));
recordID.ReadOnly = true;

//add the columns to the table
theAccessViewerTable.Columns.AddRange(new
DataColumn[]{recordID,dateColumn, userColumn, fieldColumn,
previousValueColumn, newValueColumn});
//add the tables to the data set
theDataSet.Tables.Add(theTable);
theDataSet.Tables.Add(theAccessViewerTable);
// Create a DataRelation, and add it to the DataSet.
DataRelation theDataRelation = new DataRelation("Access View",
theRecordsIDColumn , recordID);
theDataSet.Relations.Add(theDataRelation);
//if there are records load them
if(recordSet.Length > 0)
{
//loop through the records and add a row for each
foreach(Record theRecord in recordSet)
{
//grab a new row
DataRow newRow = theTable.NewRow();
//since we need to insert a value we need to populate the
array manually
//create the temp object
object[] theObjects = new
object[theRecord.dataArray.Length+1];
//insert the value in first slot
theObjects[0] = theRecord.theID;
//copy the rest of the values into the array
for(int i = 1; i < theRecord.dataArray.Length+1; i++)
{
theObjects = theRecord.dataArray[i-1];
}
//store all the items
newRow.ItemArray = theObjects;
//add the row to the table
theTable.Rows.Add(newRow);
//now we need to populate the accessView table
//loop through the entries in the viewer
foreach(AccessViewer.AccessEntry theEntry in
theRecord.accessViewer.entryList)
{
//start a new row
DataRow theAVRow = theAccessViewerTable.NewRow();
//create an object array and store the values
object[] theAVObjects = new object[]{theRecord.theID,
DateTime.Parse(theEntry.theDate), theEntry.theUsername, theEntry.theField,
theEntry.thePreviousValue, theEntry.theNewValue};
//store all the items
theAVRow.ItemArray = theAVObjects;
//add the row
theAccessViewerTable.Rows.Add(theAVRow);
}
}
}
else //no records so start a blank one
{
theTable.Rows.Add(theTable.NewRow());
}
theTable.AcceptChanges();
//store thedataset
Session["TheDataSet"] = theDataSet;
}
else
theDataSet = (DataSet)Session["TheDataSet"];
//TODO: Put event handlers back
//add the event handler used to save changes
//theTable.RowChanged += new
DataRowChangeEventHandler(theTableRowChanged);
//theTable.RowDeleting += new
DataRowChangeEventHandler(theTableRowDeleted);
//attach the DataSource;
DataView theView = new DataView(theDataSet.Tables["Records"]);
RecordDataGrid.DataSource = theView;
RecordDataGrid.DataBind();
}

Sam Samnah said:
Well the syntax looks correct. Maybe the problem is with your dataview
object. You set the table to the "Access Viewer" table maybe there is a
problem with your command string. You might want to paste all the data
processing information.
Dave Hagerich said:
Ok I removed the space and used
theView.RowFilter="RecordID=0";
and still get nothing

Sam Samnah said:
Maybe try theView.RowFilter="Record ID=0"
You might want to remove spaces from column names. I'm not sure but I think
some queries get confused with white space in column names. I'm not sure
though.


I tried that and during execution I get an exception saying it cant compare
System.Int32 with System.String
Also the name is 'Record ID' because the Column name has a space in it.

Your second line of code is wrong I think.
instead of
theView.RowFilter="'RecordID'='0'";
you can type
theView.RowFilter="RecordID=" + 0;
I think that should work. The zero looks like an int and should not
be
represented as a string.

Sam-
I'm using a DataGrid with a DataSet and I'm trying to filter the
data
being
displayed, using the following code as a test:

DataView theView = new DataView(theDataSet.Tables["Access Viewer"]);
theView.RowFilter = "'Record ID' = '0'";
theView.RowStateFilter = DataViewRowState.ModifiedCurrent;
Debug.WriteLine(string.Format("RowFilter = {0}",
theView.RowFilter));
RecordDataGrid.DataSource = theView;
RecordDataGrid.DataBind();

without the RowFilter set all the data comes up but with the RowFilter
set
I
get nothing. There is a column called Record ID and there are multiple
entries with an ID of 0. Any help would be appreciated.

Thanks,
Dave
 
It was just something to try when I wasnt getting the results I was looking
for. When I looked in the MSDN they're example set it to ModifiedCurrent
when they set the RowFilter so I fiqured I would give it a try. Of course
it didnt help any.

Sam Samnah said:
I just noticed that you set the RowStateFilter to ModifiedCurrent. You set
the table to DefaultView when you instanced the DataView Object "DataView
theView=new DataView(theDataSet.Tables["Access Viewer"]);"
Is there a reason you set the RowStateFilter to ModifiedCurrent?

Dave Hagerich said:
Ok I removed the space and used
theView.RowFilter="RecordID=0";
and still get nothing

Sam Samnah said:
Maybe try theView.RowFilter="Record ID=0"
You might want to remove spaces from column names. I'm not sure but I think
some queries get confused with white space in column names. I'm not sure
though.


I tried that and during execution I get an exception saying it cant compare
System.Int32 with System.String
Also the name is 'Record ID' because the Column name has a space in it.

Your second line of code is wrong I think.
instead of
theView.RowFilter="'RecordID'='0'";
you can type
theView.RowFilter="RecordID=" + 0;
I think that should work. The zero looks like an int and should not
be
represented as a string.

Sam-
I'm using a DataGrid with a DataSet and I'm trying to filter the
data
being
displayed, using the following code as a test:

DataView theView = new DataView(theDataSet.Tables["Access Viewer"]);
theView.RowFilter = "'Record ID' = '0'";
theView.RowStateFilter = DataViewRowState.ModifiedCurrent;
Debug.WriteLine(string.Format("RowFilter = {0}",
theView.RowFilter));
RecordDataGrid.DataSource = theView;
RecordDataGrid.DataBind();

without the RowFilter set all the data comes up but with the RowFilter
set
I
get nothing. There is a column called Record ID and there are multiple
entries with an ID of 0. Any help would be appreciated.

Thanks,
Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top