locked
Syntax Error, Missing operand after '=' operator

    Question

  • hi, i have this code to fill a data adapter in c#.net:

    this.freedomScooterServiceBindingSource.Filter = "CustomerID = " + comboBoxCustomer.SelectedValue;

    It worked fine during running of the application, but when i exit the application, it threw error "Syntax Error, Missing operand after '=' operator" on this line of code

    i checked it against some sample code, ther is no syntax error, but why is this happening?

    plz help

    Thursday, January 19, 2006 8:03 AM

Answers

  • now everything is working fine, I figured out the problem:

    it's because the comboBox control I use in the new project was copy-and-pasted from the old project, probably .net wasn't smart enough to create a new combobox object,  which caused the error.

    I got rid of this problem by simply deleting this combobox and created new one with same name, and .net automatically created an object reference.

    Sorry for my bad explanation :)

    Saturday, January 21, 2006 9:06 PM

All replies

  • ssfftt:

    I'd start be seeing whether you are missing the single quotes in your filter string. The example for BindingSource shows this:

    BindingSource1.Filter = "ContactTitle='Owner'";


    So perhaps your line of code should look like this:

    this.freedomScooterServiceBindingSource.Filter = "CustomerID = " + " ' " +  comboBoxCustomer.SelectedValue + " ' ";

    This error might also occur if comboBoxCustomer.SelectedValue is null or empty.

    Michael Blome - VIsual C# Documentation Team

    Thursday, January 19, 2006 6:20 PM
  • thx for your help Michael :)

    I put single quotes in my code, application runs no problem, however, error happened again when i exit the application, but different message:

    Cannot perform "=" operation on System.Int32 and System.String.

    btw, the selected value is set in data binding mode

    Thursday, January 19, 2006 6:40 PM
  • ssfftt,

    You should use this

    this.BindingSource.Filter = String.Format("CustomerID='{0}'",comboBoxCustomer.SelectedItem.ToString());

    Again this is where the String.Format will come in handy :-)

    I hope this has helped you!

    -Will

    Let me know if you are still having any issues with this!

    -Will

    Saturday, January 21, 2006 3:41 AM
  • Hi Will, unfortunatelly, I gave up on this problem, modified this project so that it doesn't have this form anymore. Anyway, thx for your help

    Saturday, January 21, 2006 4:01 AM
  • hi Michael, I am now working on a new project, I still get the same problem....., plz help

    in the "Data Binding Mode" of comboBoxCusName, I set "DisplayMember" to "CustomerName", the "Value Member" to "CustomerName", same column, because I only retrieve one column from the db, the query is:

    SELECT DISTINCT CustomerName FROM [Freedom Scooter Service Reminder]

    in the project, I code this:

    this.BindingSourceCusV.Filter = "CustomerName = " + "'" + comboBoxCusName.SelectedValue.ToString() + "'";

    it worked. however, again, at the end, when close/exit the application, i get an error message pointing on the line of code above:

    "NullReferenceException was unhandled ----- Object reference not set to an instance of an Object"

    why is this?

    another problem is that everytime when I select a customer name from the combobox, the listbox correctly displays services for selected customer, but the comboboxCusName itself goes wrong, the dropdown list gets messy itself, some customer names disappeared, some are duplicated. plz help

    Saturday, January 21, 2006 8:32 PM
  • now everything is working fine, I figured out the problem:

    it's because the comboBox control I use in the new project was copy-and-pasted from the old project, probably .net wasn't smart enough to create a new combobox object,  which caused the error.

    I got rid of this problem by simply deleting this combobox and created new one with same name, and .net automatically created an object reference.

    Sorry for my bad explanation :)

    Saturday, January 21, 2006 9:06 PM
  • Hi,

    Unfortunatelly I have issues with the above problem.

    I came upd to a single line of code which might be related to this:

    dataTable.Select(dataTable.Columns["country_id"].ColumnName + " = " + defCountry + " ");

    defCountry being an Int32.

    At some point(for now it seems totaly random), it throws me the same exception like the one from the begining of this thread.

    Is the Select() call finally using the Filter property?

    Many thanks,

     

    Adi

    Tuesday, August 01, 2006 2:44 PM
  • I wanto to filter datatable and one field has vlues like "Pndora's box" or so...How can I do that

     

    Wednesday, October 15, 2008 7:11 AM
  • Hi

    I have to use a query in a dataset. I need to pick the a value of a column on the basis of the passed value in another column in the same dataset. Like:

    DataRow[] dv

    dv = dsAssignments.Tables[0].Select(MaxAssignments where DivisionID = 8087);

    I need to have the value from MaxAssignments column as per the passed value in the column DivisionID. both columns are present in the dataset.

    Any help please.

     

    Wednesday, May 12, 2010 10:03 PM