티스토리 뷰
In C# prepared statements (or parameterized statements) are built via the Command object. If your database management system is SQL Server, then you will be using the SqlCommand object (instead of your regular Command object that may be used with ODBC and Access).
The Command object allows you to add parameters to a parameter collection. In turn these parameters are matched by name and the underlying functionality handles escaping and any other necessary pre-processing of your SQL statement. Here is an example:
The named parameters are @USERNAME and @PWD respectively.
The command object allows you to add SqlParameter objects to the Parameters collection. Here is one way of setting up your parameters:
The SqlCommand (or Command) object may be used to build parameterized queries and updates. The parameter usage is exactly the same with both types of operations. Because the Parameters member is a collection, when re-using the same SqlCommand object in a looping operation you must empty the collection to avoid having a crash. This removal of old parameters is done with the collection's Clear method:
Parameterized queries provide a better and cleaner approach to SQL queries in your applications. The SQL statements don't have to be sanitized in order to avoid quotation and other inconsistencies.
[출처] http://prepared-statement.blogspot.com/2006/02/c-data-access-prepared-statements.html
The Command object allows you to add parameters to a parameter collection. In turn these parameters are matched by name and the underlying functionality handles escaping and any other necessary pre-processing of your SQL statement. Here is an example:
String sql = "SELECT count(username) FROM login where username=@USERNAME and pwd=@PWD"; |
The named parameters are @USERNAME and @PWD respectively.
The command object allows you to add SqlParameter objects to the Parameters collection. Here is one way of setting up your parameters:
commandObj.Parameters.Add("@USERNAME", SqlDbType.VarChar, username.Length).Value = username; commandObj.Parameters.Add("@PWD", SqlDbType.VarChar, pwd.Length).Value = pwd; |
The SqlCommand (or Command) object may be used to build parameterized queries and updates. The parameter usage is exactly the same with both types of operations. Because the Parameters member is a collection, when re-using the same SqlCommand object in a looping operation you must empty the collection to avoid having a crash. This removal of old parameters is done with the collection's Clear method:
commandObj.Parameters.Clear(); |
Parameterized queries provide a better and cleaner approach to SQL queries in your applications. The SQL statements don't have to be sanitized in order to avoid quotation and other inconsistencies.
[출처] http://prepared-statement.blogspot.com/2006/02/c-data-access-prepared-statements.html
'웹프로그래밍 > .NET' 카테고리의 다른 글
Visual Studio 2010 과 .NET Framework 4 훈련과정 (0) | 2010.06.24 |
---|---|
[ASP.NET] ASP.NET 3.5 ListView & DataPager 사용법 (0) | 2010.06.14 |
[ASP.NET] 콧수염아저씨와 함께 배워보는 ListView 컨트롤 (0) | 2010.06.14 |
ASP.NET에서 게시판 디자인 받아서 ASP 또는 PHP 같이 작업하려면? (0) | 2010.01.03 |
[C#] 정렬 (0) | 2008.11.18 |
댓글
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- 한글
- Linux
- centos
- Mac
- sencha touch
- API
- laravel
- Android
- JQuery
- classic asp
- Debug
- javascript
- iphone
- IE
- Prototype
- git
- nginx
- CSS
- nodejs
- PHP
- iis
- IOS
- mssql
- 워드프레스
- Wordpress
- 안드로이드
- Docker
- ASP
- macos
- JSON
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
글 보관함