1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingsystem.web;5 usingSystem.Web.UI;6 usingSystem.Web.UI.WebControls;7 usingSystem.Text;8 usingSystem.Configuration;9 usingSystem.Data.SqlClient;Ten namespacevip20160413 One { A Public Partial classUserInfo:System.Web.UI.Page - { - Private stringSCon = configurationmanager.connectionstrings["Sq_ruanmou"]. ToString ();//get to the link string by a node named Sq_ruanmou theSqlConnection con =NULL;//con equals the phone . -SqlCommand cmd =NULL;//that is used to execute the SQL statement. -SqlDataReader Read =NULL;//for storing query structures - Private voidopendb () + { -Con =NewSqlConnection (sCon); +Con. Open ();//and the database was established connected A } at Private int_userid =0; - - Public intUserId - { - Get { - Try in { -_userid = request.querystring["UserId"] ==NULL?0: Convert.ToInt32 (request.querystring["UserId"]. ToString ()); to } + Catch { -_userid =0; the } * return_userid; $ }Panax Notoginseng Set{_userid =value;} - } the protected voidPage_Load (Objectsender, EventArgs e) + { A the } + Public stringgetuserinforhtml () - { $StringBuilder SB =NewStringBuilder (); $ if(UserId >0) - { -Sb. Append (@"<div class= "Das" >"); theSb. Append ("<table>"); - opendb ();Wuyi stringsSQL =string. Format ("SELECT * from Userinfor where userid={0}", UserId); the using(cmd =NewSqlCommand (sSQL, con)) - { Wu using(read =cmd. ExecuteReader ()) - { About if(read. Read ()) $ { -Sb. Append (string. Format ("<tr><td> user name:</td><td>{0}</td></tr>", read["UserName"]. ToString ())); -Sb. Append (string. Format ("<tr><td> Password:</td><td>{0}</td></tr>", read["PWD"]. ToString ())); -Sb. Append (string. Format ("<tr><td>QQ:</td><td>{0}</td></tr>", read["QQ"]. ToString ())); ASb. Append (string. Format ("<tr><td> class:</td><td>{0}</td></tr>", read["Phase"]. ToString ())); +Sb. Append (string. Format ("<tr><td> Mobile number:</td><td>{0}</td></tr>", read["Phonenum"]. ToString ())); theSb. Append (string. Format ("<tr><td> name:</td><td>{0}</td></tr>", read["Realname"]. ToString ())); - } $ } the } theSb. Append ("</table>"); theSb. Append (@"</div>"); the } - returnsb. ToString (); in } the } the}
The Code worth Learning 1