Conditional operator error with c# code on a DB update statement

I am receiving a CS1002: ; expected error with my c# code when writing a sql update statement that joins many lines of code together.  The problem line is the second one in my code example 'BD1'  Can someone assist with formatting of this line?  

NOTE: When I preview my question, I have a plus sign at the end of each line to string the lines of code together, but they are being removed.
"Last1 = '"+LName1.Text.Replace("'", "''") + "', " +
"BD1 = " string.IsNullOrEmpty(BD1.Text) == true ? "null, " + : "'"+BD1.Text.Replace("'", "''") + "', " +;
"First2 = '"+FName2.Text.Replace("'", "''") + "', " +

Open in new window

fairway01Asked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
please learn to do parameterized queries, that will make your code simpler, and avoid sql injection.
kick-off: http://www.java2s.com/Code/CSharp/Database-ADO.net/PassparameterstoSqlCommand.htm
0
 
HarryNSCommented:
string strLName1 = "Last1 = '" + LName1.Text.Replace("'", "''") + "', ";
            string strFName1 = "First2 = '" + FName2.Text.Replace("'", "''") + "', ";
            string strBD1 = "BD1 = " + ((string.IsNullOrEmpty(BD1.Text) == true) ? "null, " : "'" + BD1.Text.Replace("'", "''") + "', ");

            string strResult = strLName1 + strBD1 + strFName1;

Use the above one OR

string strResult = "Last1 = '" + LName1.Text.Replace("'", "''") + "', " +
                "First2 = '" + FName2.Text.Replace("'", "''") + "', " +
                "BD1 = " + ((string.IsNullOrEmpty(BD1.Text) == true) ? "null, " : "'" + BD1.Text.Replace("'", "''") + "', ");
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.