?
Solved

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

Posted on 2009-04-20
3
Medium Priority
?
276 Views
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

0
Comment
Question by:fairway01
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 24184378
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
 
LVL 6

Assisted Solution

by:HarryNS
HarryNS earned 1000 total points
ID: 24184448
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Integration Management Part 2
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

831 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