Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filter error on Bindingsource

Status
Not open for further replies.

patrickstrijdonck

Programmer
Jan 18, 2009
97
NL
Hello,

In my Treeview, the bindingsource for my Datagrid must be updated with a filter. Currently I have this piece of code that must do that
Code:
            // Get Storenumber from Storename
            string command3;
            string cmdemailasm3 = Properties.Settings.Default.IT4ConnectionString1;

            command3 = @"SELECT Storenr FROM tblStores WHERE Storenaam = @name";
            OleDbConnection connemailasm3 = new OleDbConnection(cmdemailasm3);
            OleDbCommand comemailasm3 = new OleDbCommand(command3, connemailasm3);

            comemailasm3.Parameters.AddWithValue("@name", SqlDbType.VarChar);
            comemailasm3.Parameters["@name"].Value = e.Node.Text;
            
            connemailasm3.Open();
            outstandingCallsBindingSource1.Filter = Convert.ToString(comemailasm3.ExecuteScalar());
            connemailasm3.Close();

But an error occurs,

Filter expression '7622' does not evaluate to a Boolean term (*where 7622 is the storenumber which is picked up from the database)

Any idea what im doing wrong here?
 
you are calling AddWithValue, but you are not including the value, only the name and data type. try
Code:
var value = e.Node.Text;
comemailasm3.Parameters.AddWithValue("@name", value, SqlDbType.VarChar);
or something like that.

there is also a lot you can do to clean this code up. calling dispose in a finally block, or using the "using" keyword to start.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Hey Jason,

I am actually including a value,

Code:
            comemailasm3.Parameters.AddWithValue("@name", SqlDbType.VarChar);
            comemailasm3.Parameters["@name"].Value = e.Node.Text;

e.Node.Text is the text which is for the selected node.

and the code you provided gave an error in visual studio,...

"No overload for method 'AddWithValue' Takes 3 Arguments
 
Either do this.
[tt]
comemailasm3.Parameters.AddWithValue("@name", [red]e.Node.Text[/red]);
[red]//[/red]comemailasm3.Parameters["@name"].Value = e.Node.Text;
[/tt]
Or that.
[tt]
comemailasm3.Parameters.[red]Add[/red]("@name", SqlDbType.VarChar);
comemailasm3.Parameters["@name"].Value = e.Node.Text;[/tt]
 
Both is not working for me,....

Still getting the error at this point;
(Filter expression '7622' does not evaluate to a Boolean term)
Code:
outstandingCallsBindingSource1.Filter = Convert.ToString(comemailasm3.ExecuteScalar());
 
Found it out, Change that part of code to
Code:
OutstandingTreeviewCalls.Filter = "Store=" + Convert.ToString(comemailasm3.ExecuteScalar());

What I forgot was to say in the command on which field it should filter, which was field "Store".

Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top