13.07.2015 Views

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

282<strong>ASP</strong>.<strong>NET</strong> <strong>3.5</strong>: A Beginner’s <strong>Guide</strong>Ask the ExpertQ: I’ve noticed that in some of the queries that the letter N is used before a string literal,like N'Brauns' in one of the UPDATE statement examples. What is the N for?A: Use the letter N or n before a string literal to ensure it uses the Unicode character set inSQL server. The N was so selected because it means national character set (Oracle andANSI). In the examples in this book, I’ve left it out to help reduce clutter, but you canadd it to any of the examples that use string literals. Also, you will find the N added toany string literals in queries you make in Visual Studio 2008 in the Query mode.one operation. Typically, you will need to specify the exact record to change by specifyingvalues of its content. This operation may involve several fields and takes the general formatUPDATE TableName SET fieldToChange = newValue WHERE field1=value1 AND field2=value2For example, if you want to update the amount in a donation field, you either need tospecify the unique ID in the primary key or use a specific name that you are certain hasno duplicates:UPDATE Supporters SET Donation = newAmount WHERE (LastName = N'Brauns' ANDFirstName = N'Lelia')The value of newAmount can either be a literal or a variable. Most likely you wouldwant to add the amount as a variable based on the previous amount that had been donated.This process would involve first getting the original amount and adding it in a C# variableto the new amount.Multiple Record UPDATEOn some occasions, you will need to update several records simultaneously. The processis exactly the same as when updating a single class. For example, suppose you havea table with one field for the <strong>com</strong>pany name. If one of your clients changes its name from“Sandlight” to “SandlightSoft,” you can change the field name by setting the update withfewer parameters than when looking for a single record to update. The following SQLstatement changes all records where the single change needs to be made but may affectmultiple records:UPDATE AcmeWareTable SET Company = 'SandlightSoft' WHERE Company = 'Sandlight'

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!