Learn small exercises 1

zhaozj2021-02-16  71

1, login test

A:

Namespace test {? ///

? /// WebForm1's summary description. ? ///

PUBLIC CLASS Login: System.Web.ui.page

? {

?? protected system.Web.ui.WebControls.TextBox txtuserid;

?? protected system.web.ui.webcontrols.textbox txtpassword;

?? protected system.Web.ui.webcontrols.button button1;

?? protected system.web.ui.webcontrols.button button2;

?? String userid;

?? String password;

?

?? Private void Page_load (Object Sender, System.EventArgs E)

?? {

??? // Place the user code here to initialize the page

??}

?? # Region Web Form Designer generated code ?? override protected void oninit (Eventargs E) ?? {??? // ??? // codegen: This call is necessary for the ASP.NET Web Form Designer. ??? // ??? INITIALIZECMPONENT (); ??? Base.onit (E); ??} ???? ////

?? /// Designer supports the required method - do not use the code editor to modify ?? // This method. ?? ///

?? private void initializecomponent ()

?? {???

??? this.button1.click = new system.eventhandler (this.button1_click);

??? this.load = new system.eventhandler (this.page_load);

??} ?? # endregion

?? private void Button1_Click (object sender, System.EventArgs e) ?? {??? SqlConnection myConnection = new SqlConnection ( "data source = (local); user id = sa; password = qazwsx1; initial catalog = test;") ; ??? sqlcommand mycommand = new sqlcommand ("SELECT Userid, Password from [user] where userid = @Userid", myconnection); ?????? userid = txtuserid.text; ??? password = txtpassword.text;

??? mycommand.parameters.add ("@ userid", sqldbtype.nvarchar, 50) .value = userid;

??? myconnection.open (); ??? sqldataraduter DR = mycommand.executeReader (); // ??? BOOL EXIST = false; // ??? While (Dr.Read ()) // ??? { // ???? if (! exist) // ???? {// ????? UserId == DR [0] .tostring (); // ????? password == DR [1 ] .Tostring (); // ????? EXIST = true; // ????? response.redirect ("success.aspx"); // ????? // ????} / / ???? Break; // ???} ??? if (! Dr.read ()) ???? response.redirect ("fail.aspx"); ??? IF (DR [1]. TOSTRING () == password) ???? response.redirect ("success.aspx"); ??? Else ???? response.redirect ("fail.aspx"); ??}?}}?

B:

Namespace test {? ///

"/// denglu's summary description. ? ///

Public Class Denglu: System.Web.ui.page

? {

?? protected system.web.ui.webcontrols.textbox txtusername

?? protected system.web.ui.webcontrols.textbox txtpassword;

?? protected system.Web.ui.webcontrols.button button1;

?? protected string userid;

?? protected;

?

?? Private void Page_load (Object Sender, System.EventArgs E)

?? {

??? // Place the user code here to initialize the page

??}

?? # Region Web Form Designer generated code ?? override protected void oninit (Eventargs E) ?? {??? // ??? // codegen: This call is necessary for the ASP.NET Web Form Designer. ??? // ??? INITIALIZECMPONENT (); ??? Base.onit (E); ??} ???? ////

?? /// Designer supports the required method - do not use the code editor to modify ?? // This method. ?? ///

?? private void initializecomponent ()

?? {???

??? this.button1.click = new system.eventhandler (this.button1_click);

??? this.load = new system.eventhandler (this.page_load);

??} ?? # endregion

?? private void Button1_Click (object sender, System.EventArgs e) ?? {??? SqlConnection myConnection = new SqlConnection ( "data source = (local); user id = sa; password = qazwsx1; initial catalog = test;") ??? SQLCommand mycommand = new sqlcommand ("Select * from [user] where userid = @ userid", myconnection); ??? Userid = txtusername.text; ??? password = txtpassword.text; ??? mycommand. Parameters.add ("@ userid", sqldbtype.nvarchar, 50) .value = userid; ??? myconnection.open (); ??? sqldatareader DR = mycommand.executeReader (); ??? f (Dr.read) )) ???? f (password == DR [1] .tostring ()) ????? response.redirect ("success.aspx"); ????? Else ?????? response. Redirect ("fail.aspx"); ??? Else ???? Response.Redirect ("fail.aspx");

??}?}}

?

2, press release

Add to:

Namespace Test.news {? ///

"/// news_add summary description. ? ///

PUBLIC CLASS News_ADD: System.Web.ui.page

? {

?? protected system.Web.ui.webcontrols.textbox txtttitle;

?? protected system.Web.ui.webcontrols.textbox txtcontent

?? protected system.web.ui.webcontrols.button btnok;

?? protected string title;

?? protected string content;

?

?? Private void Page_load (Object Sender, System.EventArgs E)

?? {

??? // Place the user code here to initialize the page

??}

?? # Region Web Form Designer generated code ?? override protected void oninit (Eventargs E) ?? {??? // ??? // codegen: This call is necessary for the ASP.NET Web Form Designer. ??? // ??? INITIALIZECMPONENT (); ??? Base.onit (E); ??} ???? ////

?? /// Designer supports the required method - do not use the code editor to modify ?? // This method. ?? ///

?? private void initializecomponent ()

?? {???

??? this.btnok.click = new system.eventhandler (this.btnok_click);

??? this.load = new system.eventhandler (this.page_load);

??} ?? # endregion

?? private void btnOk_Click (object sender, System.EventArgs e) ?? {??? SqlConnection myConnection = new SqlConnection ( "data source = (local); user id = sa; password = qazwsx1; initial catalog = test;") ; ??? sqlcommand mycommand = new sqlcommand ("INSERT INTO NEWS (Title, Content)", "@ title, @ Content)", myconnection; ??? title = txttitle.text; ??? content = txtcontent.text;

??? mycommand.parameters.add ("@ title", sqldbtype.nvarchar, 50) .value = Title; ??? mycommand.parameters.add ("@ Content", Sqldbtype.Nvarchar, 500) .value = Content;

??? myconnection.open (); ??? mycommand.executenonquery (); ??}?}}

List:

Namespace Test.news {? ///

"/// news_list's summary description. ? ///

PUBLIC CLASS News_List: System.Web.ui.page

? {

?? protected system.web.ui.WebControls.dataGrid dgtitle;

?

?? Private void Page_load (Object Sender, System.EventArgs E)

?? {

??? // Place the user code here to initialize the page

??? sqlconnection myconnection = new sqlconnection ("data source = (local); user ID = sa; password = QAZWSX1; Initial Catalog = TEST;");

??? String Selcom = "SELECT ID, TIM News";

??? SqlDataAdapter mydataadapter = new sqldataadapter (Selcom, MyConnection);

// ??? String ID = Request.QueryString ["ID"];

///???mydataadapter.selectcommand.parameters.add(new SqlParameter ("@ ID", SQLDBTYPE.NVARCHAR, 500)). VALUE = ID;

??? DataSet DS = new dataset (); ??? mydataadapter.Fill (DS, "TBLCONTENT"); ??? DataView DV; ??? DV = ds.tables ["tblContent"]. Defaultview;

??? DGTILE.DATASOURCE = DV; ??? dgtitle.database (); ??}

?? # Region Web Form Designer generated code ?? override protected void oninit (Eventargs E) ?? {??? // ??? // codegen: This call is necessary for the ASP.NET Web Form Designer. ??? // ??? INITIALIZECMPONENT (); ??? Base.onit (E); ??} ???? /// ?? /// designer supports the required method - do not use the code editor Modify ?? // / This method's content. ?? ///

?? private void initializecomponent ()

?? {???

??? this.dgtitle.pageIndexchanged = new system.web.ui.webcontrols.dataGridPageChangeDeventHandler (this.dgtitle_pageindexchanged);

??? this.load = new system.eventhandler (this.page_load);

??} ?? # endregion

?? Private void DGTILE_PAGEINDEXCHANGED (Object Source, System.Web.ui.WebControls.DataGridPageChangeDeventargs e) ?? {??? dgtitle.currentpageIndex = E.NEWPAGEINDEX;

??? DGTILE.DATABIND ();??}?}}

detailed:

Namespace Test.news {? ///

"/// news_detial's summary description. ? ///

PUBLIC CLASS News_DETIAL: System.Web.ui.page

? {

?? protected system.web.ui.webcontrols.label labcontent

?

?? Private void Page_load (Object Sender, System.EventArgs E)

?? {

??? // Place the user code here to initialize the page

??? sqlconnection myconnection = new sqlconnection ("data source = (local); user ID = sa; password = QAZWSX1; Initial Catalog = TEST;");

??? SQLCommand mycommand = new sqlcommand ("SELECT Content from News Where

ID = @ ID ", myConnection);

??? String ID = Request.QueryString ["ID"];

??? mycommand.parameters.add ("@ id", sqldbtype.nvarchar, 500) .value = ID;

??? myconnection.open (); ??? sqldatareader dr = mycommand.executeRead (commandbehavior.singlerow); ??? if (DR.READ ()) ??? {???? Labcontent.visible = true ;? ??? Labcontent.text = DR [0] .tostring (); ???} // ??? ELSE

??}

?? # Region Web Form Designer generated code ?? override protected void oninit (Eventargs E) ?? {??? // ??? // codegen: This call is necessary for the ASP.NET Web Form Designer. ??? // ??? INITIALIZECMPONENT (); ??? Base.onit (E); ??} ???? /// ?? /// designer supports the required method - do not use the code editor Modify ?? // / This method's content. ?? ///

?? private void initializecomponent ()

?? {???

??? this.load = new system.eventhandler (this.page_load);

??} ?? # endregion?}}

转载请注明原文地址:https://www.9cbs.com/read-14884.html

New Post(0)