Syntax error: Missing operand after 'Name' operator.

Any help would be great. I'm trying to setup a filter for my address book program that uses an Access database. I have it working for a different form and I did it the same way as far as I know. For some reason though on this form I get the error "Syntax error: Missing operand after 'Name' operator." Here is the line of code that gives me the error:

Me.PhoneBindingSource.Filter = _
String.Format("{0} like '%{1}%'", _
Me.PIDSDataSet2.Phone.Last_NameColumn, _
Me.FilterTextBox.Text)


Answer this question

Syntax error: Missing operand after 'Name' operator.

  • SerenityNever

    It sounds as though you may have changed one and not the other - so they got out of sync.

    The database field and the dataset field are not dynamically linked together. If they are different then you have to be careful about which one you are using for SQL statements, Filter statements etc.


  • Dan-el

    from the code example you provided

    Me.PhoneBindingSource.Filter = _
    String.Format("{0} like '%{1}%'", _
    Me.PIDSDataSet2.Phone.Last_NameColumn, _
    Me.FilterTextBox.Text)


    If this is working on the other form then I would check that the current form your using this on has a Dataset called PIDSDataset2 which contains a Phone table with a Last_NameColumn field in it.

    Normally the filter statement would be something like

    'FieldName like '%foo%'"

    In which case I would assume that Me.PIDSDataSet2.Phone.Last_NameColumn contains the name of the column which you are going to be doing the comparison on.

    Have you checked that this actually contains anything.


  • Mike F

    Thank you for the reply spotty. I do have a Dataset called PIDSDataset2 with a Phone table in it with a column called Last Name in it. I had to put the _ in there because I don't believe you can just put spaces and it has the word Column after Last_Name because that is telling it what column to look in for the comparison. I'm learning about bindingsource and datasets which I believe are new to .net. I must be overlooking something though and for 2 weeks I have not been able to figure out what it is. Any other ideas

  • amadeus1eu

    The field names can have spaces in them but it is generally not good practice as you then have to wrap the individual field names in [ ] to indicate the extent of the field names.

    So from what you telling me you have a field called Last_NameColumn in the PIDSDataset.

    Try the following line

    Me.PhoneBindingSource.Filter = " Last_NameColumn like '%%'"

    and see if this produces any records.

    You look as though your providing it with a field - but the filter statement is simply trying to produce a filter SQL Statement and therefore you want to provide it with the field name and not the field.

    If the above seems to work without error then try the following.

    Me.PhoneBindingSource.Filter = _
    String.Format("{0} like '%{1}%'", _
    "Last_NameColumn", _
    Me.FilterTextBox.Text)


  • S. Unal

    Good news, I got it working! Your code helped me out. It said it could not find the Last_Name column. I looked and it was there! There is a place though where you can change the name to LastColumn in the DataSet without changing it in the database itself. It worked fine then. Maybe the _ doesn't work well or at all in place of spaces in this kind of situation.
  • Syntax error: Missing operand after 'Name' operator.