Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm with Stephen Wrighton. There are a LOT of variables here, and a lot of unanswered questions. If it's SQL, is it even a Microsoft dialect of SQL? Is it Oracle? MySQL? Something else?</p> <p>In any event, my personal preference is to avoid building SQL in an application if I can, and invoke a stored procedure, even for inserts and updates. Then I pass the arguments for the procedure to the ADO.NET command object. I have this insane idea in my head that SQL belongs in the database. Perhaps that comes from all that time I spent debugging horrifically written ASP code that spliced SQL strings together back in the Dot Com era. (Never again.)</p> <p>If you feel it's absolutely necessary to do so, meet the <a href="http://msdn.microsoft.com/en-us/library/system.text.stringbuilder.aspx" rel="nofollow noreferrer">System.Text.StringBuilder</a> class. Learn it. Love it. Make it your best friend. </p> <p><strong>UPDATE:</strong> Seeing your response, I see now that you are working with SQL Server. That makes things much better.</p> <p>I'd recommend separating your SQL code into a separate class, away from the actual business class. Some might not agree with that, but it will keep the PURPOSE of the classes clear. (See <a href="http://en.wikipedia.org/wiki/Separation_of_concerns" rel="nofollow noreferrer">Separation of Concerns</a>.) </p> <p>You want to have your business object handle the business logic, and a separate class that handles the work of getting data into and out of the database. That way, if you have a problem with the serialization logic, you have a far better idea of where to look, and your chances of hosing the business logic are greatly reduced. It also makes your application much easier to understand.</p> <p>A little up front effort in writing a few more classes has a HUGE payoff down the road.</p> <p>But that's just my opinion.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload