24. 24
Nhu c畉u c畉n c坦 truy v畉n c坦 tham s畛
Ch炭ng ta th動畛ng vi畉t c叩c c但u l畛nh SQL 畛 t狸m
ki畉m c叩c d嘆ng d畛 li畛u trong CSDL theo m畛t i畛u
ki畛n no 坦. Nh畛ng gi叩 tr畛 trong i畛u ki畛n do
ng動畛i d湛ng nh畉p vo
V鱈 d畛: T狸m ki畉m nh但n vi棚n c坦 trong CSDL kh担ng
畛 cho ph辿p ng nh畉p vo ch動董ng tr狸nh
string strUser, strPass;
strUser = txtUser.Text;
strPass = txtPass.Text;
string strSQL;
strSQL = "select * from NhanVien where " +
"username='" + strUser + "' and " +
"password='" + strPass + "'";
25. 25
Nhu c畉u c畉n c坦 truy v畉n c坦 tham s畛
Nh畉n x辿t
B畉t k畛 nh畛ng g狸 nh畉p vo txtPass, txtUser 畛u
動畛c 畉t vo trong c但u SQL
H達y nh畉p vo username: ' or ('1'='1') or '1'='1 hay
H達y nh畉p vo password: ' or '1'='1
26. 26
Nhu c畉u c畉n c坦 truy v畉n c坦 tham s畛
Truy v畉n c坦 tham s畛
Nh畛ng n董i trong c但u SQL c畉n d畛 li畛u ng動畛i
d湛ng, ch炭ng ta s畉 t畉o nh畛ng tham s畛 t畉i
nh畛ng n董i 坦 (g畛i l parameter placeholders)
B畉t k畛 d畛 li畛u g狸 動畛c truy畛n vo tham s畛 s畉
動畛c 畛i x畛 nh動 l d畛 li畛u thu畉n t炭y (kh担ng
ph畉i l 1 c但u l畛nh SQL)
#7: Data Manipulation Language
Data Definition Language
#9: Kiem tra xem select kh坦a chinh c坦 tra ve 1 gi叩 tr畛 hay kh担ng
Select 1cot
From bang
Where cot_khoa_chinh = giaitr
Select 1cot
From bang
Where cot_duynhat = giaitr
#31: BigIntInt64. A 64-bit signed integer.
BinaryArray of type Byte. A fixed-length stream of binary data ranging between 1 and 8,000 bytes.
BitBoolean. An unsigned numeric value that can be 0, 1, or nullNothingnullptra null reference (Nothing in Visual Basic).
CharString. A fixed-length stream of non-Unicode characters ranging between 1 and 8,000 characters.
DateTimeDateTime. Date and time data ranging in value from January 1, 1753 to December 31, 9999 to an accuracy of 3.33 milliseconds.
DecimalDecimal. A fixed precision and scale numeric value between -10 38 -1 and 10 38 -1.
FloatDouble. A floating point number within the range of -1.79E +308 through 1.79E +308.
ImageArray of type Byte. A variable-length stream of binary data ranging from 0 to 2 31 -1 (or 2,147,483,647) bytes.
IntInt32. A 32-bit signed integer.
MoneyDecimal. A currency value ranging from -2 63 (or -9,223,372,036,854,775,808) to 2 63 -1 (or +9,223,372,036,854,775,807) with an accuracy to a ten-thousandth of a currency unit.
NCharString. A fixed-length stream of Unicode characters ranging between 1 and 4,000 characters.
NTextString. A variable-length stream of Unicode data with a maximum length of 2 30 - 1 (or 1,073,741,823) characters.
NVarCharString. A variable-length stream of Unicode characters ranging between 1 and 4,000 characters. Implicit conversion fails if the string is greater than 4,000 characters. Explicitly set the object when working with strings longer than 4,000 characters.
RealSingle. A floating point number within the range of -3.40E +38 through 3.40E +38.
UniqueIdentifierGuid. A globally unique identifier (or GUID).
SmallDateTimeDateTime. Date and time data ranging in value from January 1, 1900 to June 6, 2079 to an accuracy of one minute.
SmallIntInt16. A 16-bit signed integer.
SmallMoneyDecimal. A currency value ranging from -214,748.3648 to +214,748.3647 with an accuracy to a ten-thousandth of a currency unit.
TextString. A variable-length stream of non-Unicode data with a maximum length of 2 31 -1 (or 2,147,483,647) characters.
TimestampArray of type Byte. Automatically generated binary numbers, which are guaranteed to be unique within a database. timestamp is used typically as a mechanism for version-stamping table rows. The storage size is 8 bytes.
TinyIntByte. An 8-bit unsigned integer.
VarBinaryArray of type Byte. A variable-length stream of binary data ranging between 1 and 8,000 bytes. Implicit conversion fails if the byte array is greater than 8,000 bytes. Explicitly set the object when working with byte arrays larger than 8,000 bytes.
VarCharString. A variable-length stream of non-Unicode characters ranging between 1 and 8,000 characters.
VariantObject. A special data type that can contain numeric, string, binary, or date data as well as the SQL Server values Empty and Null, which is assumed if no other type is declared.
XmlAn XML value. Obtain the XML as a string using the GetValue method or Value property, or as an XmlReader by calling the CreateReader method.
UdtA SQL Server 2005 user-defined type (UDT).
StructuredA special data type for specifying structured data contained in table-valued parameters.
DateDate data ranging in value from January 1,1 AD through December 31, 9999 AD.
TimeTime data based on a 24-hour clock. Time value range is 00:00:00 through 23:59:59.9999999 with an accuracy of 100 nanoseconds.
DateTime2Date and time data. Date value range is from January 1,1 AD through December 31, 9999 AD. Time value range is 00:00:00 through 23:59:59.9999999 with an accuracy of 100 nanoseconds.
DateTimeOffsetDate and time data with time zone awareness. Date value range is from January 1,1 AD through December 31, 9999 AD. Time value range is 00:00:00 through 23:59:59.9999999 with an accuracy of 100 nanoseconds. Time zone value range is -14:00 through +14:00.