C# question - probably easy

I am trying to add a string to an SQL statement based on whether an asp:checkbox is checked. Below is what I have, and it isnt working.

I know I could set comm inside the if statement, but I imagine there is a way just to add a variable string to the SQL.

    string IndCBSQL;
    if (iIndividualsCheckBox.Checked)
    {
        [COLOR="Red"]IndCBSQL[/COLOR] = "AND CMMaster.CONSTTYPE LIKE 'Individual'";
    }
    string City = rCity.Text + '%';
    [COLOR="blue"]comm[/COLOR] = new SqlCommand(
        "SELECT CMMaster.CONTEXIST, CMMaster.IDNUMBER, CMMaster.MAIL_NAME, CMMaster.ADD1, CMMaster.CITY, CMMaster.STATE, CMMaster.ZIP, FROM [CFS].[dbo].[CMMaster] WHERE CMMaster.City LIKE @City" + [COLOR="red"]IndCBSQL[/COLOR], conn);

thanks for the help!

This is going to sound silly but try adding a space before AND.

" AND CMMaster.CONSTTYPE LIKE ‘Individual’";

Right now your sql statement looks like this:
… LIKE @CityAND CMMaster.CONSTTYPE LIKE ‘Individual’"

@CityAND doesn’t make sense, right?

that probably would have been a problem later, but the above doesnt even compile.

I get the following error in the SQLCommand statement

Error 1 Use of unassigned local variable ‘IndCBSQL’

string IndCBSQL= string.Empty;

that’s it. thanks a bunch.

and imaginekitty - you probably saved me from an sql error. thanks!

What do you know…Just started reading a c# book and chapter two talks about the Definite Assignment Rule.

Hey, I never knew what that was called. Interesting.