StreamRead, sqlparamter, and SQL connection Query

Source: Internet
Author: User
StreamRead and sqlparamter, SQL connection query and paging

StreamRead, sqlparamter, SQL connection query, and paging sorting-the Xml operation InnerText will escape the tag InnerXml and will not delegate the tag escape to multicast. -- write txt StreamWrite into text reader. fieldCount obtains the number of fields. The WriteLine () method of the StreamWrite object can write the read content

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.

,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.