StreamRead and sqlparamter, SQL connection query and paging
-> Xml operations
InnerText will escape tags <>
InnerXml does not escape tags
Delegate
Multicast delegate.
-- Write txt
StreamWrite writes reader. FieldCount to get the number of fields
The WriteLine () method of the StreamWrite object can write the read content to the txt file.
StreamRead reads text
String temp;
While (temp = reader. ReadLine ())! = Null) indicates reading data.
// Removes the auto-increment id.
Temp = Regex. Replace (temp, @ "^ \ d + ,","");
String [] strs = temp. split (new char [] {',', StringSplitOptions. RemoveEmptyEnetits}
// Write the data to the database if the length is 10.
// The id 0 in the lower table of strs does not need auto-increment data.
If (strs. leng = 10)
{
String sqlTemp = string. format (SQL, strs );
}
-- Prevent SQL Injection
// 2. Bind your input to the parameter alias and use the sqlParamter class
SqlParameter p1 = new SqlParameter ("@ username", uid );
SqlParameter p2 = new SqlParameter ("@ password", pwd );
// Add it to cmd
Cmd. Parameters. Add (p1 );
Cmd. Parameters. Add (p2 );
-- Add the simplest sqlparameter object
Cmd. Parameters. AddWithValue ("@ username", username );
-- Cross Query
Mainly used in auxiliary tables
Select t2.num * 10, t1.num + 1 from tblnumber as t1 cross join tblnumber as t2;
Generate the number order by 1 from 1 to; sort from 1
-- Internal Link
-- External link
-- Use one query as the data source for another query (derived table)
-- Query (order by is not allowed unless order by and top are used together)
As a data source, put it behind the from and use parentheses to get the alias as t1 (result set)
-- Use the alias pilot field in select.
-- Pagination ***
C #
-Math. Celling (): function for returning the current page
(Int) Math. Ceiling (rows * 1.0/10 );
Lable Text box. Text = string. format ("{0}/{1}", 1, CountPage); -- CountPage total number of pages
Lable Text box. text = Regex. Replace (Text in the lable text box, @ "^/d +/", Page + "/");
Is to find the number/Replace with page /;
-- Paging
Between 1 and 10; Statement
Select * from student where
Stuid between (@ page-1) * @ count + 1 and (@ page * count );
2-1*5 + 1 and 2*5
-- Introduce a ranking function Row_Number () in sqlserver 2005.
Row_Number () over (order by StuName); the rows must follow the over () sorting rule.