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

Posted on 2009-04-20
Last Modified: 2013-12-17
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

Question by:fairway01
    LVL 142

    Accepted Solution

    please learn to do parameterized queries, that will make your code simpler, and avoid sql injection.
    LVL 6

    Assisted Solution

    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("'", "''") + "', ");

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Suggested Solutions

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now