1. Development environment vs 2013,sqlserver 2012,win 8.1x64,c# language,. NET 4.5
2. Better to explain
The humanization of contacts and additions and changes
3. Web page effects
1. Home page:
2. View all Contacts
3. Find the contact person for the student in the Occupation:
4. Find the contact for the named person:
5. Add a Contact:
6. After adding:
7. Update the Contact:
8. Before the update:
9. After the update:
10. Delete a contact:
11. Before deleting:
12. After deletion:
13. About:
4. Key code: Default.aspx:
<%@ page title= "Delete" language= "C #" masterpagefile= "~/site.master" autoeventwireup= "true" codefile= " Delete.aspx.cs "inherits=" Delete "%><asp:content id=" bodycontent "contentplaceholderid=" maincontent "runat=" Server > <p> </p> <p> </p> <p> &NBSP;</P&G T <p> </p> <p> <asp:linkbutton id= "LinkButton1" runat= "Server" onclick= "Linkbutt On1_click "> See all Contacts </asp:LinkButton> </p> <p> All contacts below, please enter the name or number of the person to be deleted or the phone number: </p><p> ; Delete:</p><p> <asp:textbox id= "Phone" runat= "server" ></asp:TextBox> <asp:button by phone number Id= "Button1" runat= "Server" onclick= "Button1_Click" text= "delete"/></p><p> delete:</p><p> < by name ; Asp:textbox id= "Name" runat= "Server" ></asp:TextBox> <asp:button id= "Button2" runat= "Server" onclick= "button2_click" text= "Delete"/></P≫<p> Delete:</p><p> <asp:textbox id= "id" runat= "server" ></asp:TextBox> <as by number P:button id= "Button3" runat= "Server" onclick= "button3_click" text= "delete"/></p><p> </p>< p> <asp:gridview id= "GridView1" runat= "Server" width= "739px" > </asp:GridView></p> </asp:con Tent>
Default.aspx.cs:
Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.UI;using System.web.ui.webcontrols;using system.data.sqlclient;using system.data;public partial class _default:page{Protecte d void Page_Load (object sender, EventArgs e) {} protected void LinkButton1_Click (object sender, EventArgs e) {string constring= "Data source= (LocalDB) \\v11.0; Attachdbfilename=d:\\userfile\\documents\\visual Studio 2013\\websites\\website5\\app_data\\contact.mdf;i ntegrated security=true "; String SQL1 = "SELECT * from"; SqlConnection myconn = new SqlConnection (constring); SqlCommand mycmd = new SqlCommand (SQL1, myconn); SqlDataAdapter SDA = new SqlDataAdapter (myCMD); DataSet ds = new DataSet (); Sda. Fill (ds, "Contact"); This. Gridview1.datasource = ds. tables["Contact"]; This. Gridview1.databind (); MyConn. Close (); } protected void button1_click (object sender, EventArgs e) {String constring = "Data source= (LocalDB) \\v11.0; Attachdbfilename=d:\\userfile\\documents\\visual Studio 2013\\websites\\website5\\app_data\\contact.mdf;i ntegrated security=true "; String SQL1 = "SELECT * from Contact where name= '" +this. Name.Text.ToString (). Trim () + "';"; SqlConnection myconn = new SqlConnection (constring); SqlCommand mycmd = new SqlCommand (SQL1, myconn); SqlDataAdapter SDA = new SqlDataAdapter (myCMD); DataSet ds = new DataSet (); Sda. Fill (ds, "Contact"); This. Gridview1.datasource = ds. tables["Contact"]; This. Gridview1.databind (); MyConn. Close (); } protected void Button2_Click (object sender, EventArgs e) {string constring = "Data source= (LocalDB) \\v11.0 ; Attachdbfilename=d:\\userfile\\documents\\visual Studio 2013\\websites\\website5\\app_data\\contact.mdf;i ntegrated security=true "; String SQL1 = "SELECT * from Contact where address= '" +this. address.text+ "';"; SqlConnectIon myconn = new SqlConnection (constring); SqlCommand mycmd = new SqlCommand (SQL1, myconn); SqlDataAdapter SDA = new SqlDataAdapter (myCMD); DataSet ds = new DataSet (); Sda. Fill (ds, "Contact"); This. Gridview1.datasource = ds. tables["Contact"]; This. Gridview1.databind (); MyConn. Close (); } protected void Button3_Click (object sender, EventArgs e) {string constring = "Data source= (LocalDB) \\v11.0 ; Attachdbfilename=d:\\userfile\\documents\\visual Studio 2013\\websites\\website5\\app_data\\contact.mdf;i ntegrated security=true "; String SQL1 = "SELECT * from the contact where vocation= '" +this.vocation.text+ "';"; SqlConnection myconn = new SqlConnection (constring); SqlCommand mycmd = new SqlCommand (SQL1, myconn); SqlDataAdapter SDA = new SqlDataAdapter (myCMD); DataSet ds = new DataSet (); Sda. Fill (ds, "Contact"); This. Gridview1.datasource = ds. tables["Contact"]; This. Gridview1.dataBind (); MyConn. Close (); } protected void Vocation_textchanged (object sender, EventArgs e) {}}
Add.aspx:
<%@ page title= "Add" language= "C #" masterpagefile= "~/site.master" autoeventwireup= "true" codefile= "Add.aspx.cs" inherits= "Add"%><asp:content id= "bodycontent" contentplaceholderid= "maincontent" runat= "Server" > <div class= "Jumbotron" >
Add.aspx.cs:
Using system;using system.collections.generic;using system.data;using system.data.sqlclient;using System.Linq;using System.web;using system.web.ui;using system.web.ui.webcontrols;public partial class add:system.web.ui.page{Protecte d void Page_Load (object sender, EventArgs e) {string tempname = this. Name.Text.Trim (); String constring = "Data source= (LocalDB) \\v11.0; Attachdbfilename=d:\\userfile\\documents\\visual Studio 2013\\websites\\website5\\app_data\\contact.mdf;i ntegrated security=true "; String SQL1 = "SELECT * from"; SqlConnection myconn = new SqlConnection (constring); SqlCommand mycmd = new SqlCommand (SQL1, myconn); SqlDataAdapter SDA = new SqlDataAdapter (myCMD); DataSet ds = new DataSet (); Sda. Fill (ds, "Contact"); This. Gridview1.datasource = ds. tables["Contact"]; This. Gridview1.databind (); MyConn. Close (); } protected void Submit_click (object sender, EventArgs e) {StriNg Tempname=this. Name.Text.Trim (); String constring = "Data source= (LocalDB) \\v11.0; Attachdbfilename=d:\\userfile\\documents\\visual Studio 2013\\websites\\website5\\app_data\\contact.mdf;i ntegrated security=true "; string sql1 = "INSERT into contact values (@ID, @name, @address, @phonenumber, @age, @sex, @vocation)"; SqlConnection myconn = new SqlConnection (constring); SqlCommand mycmd = new SqlCommand (SQL1, myconn); myCMD. Parameters.Add (New SqlParameter ("@ID", SqlDbType.Int)); myCMD. Parameters.Add (New SqlParameter ("@name", SqlDbType.NVarChar, 50)); myCMD. Parameters.Add (New SqlParameter ("@address", SqlDbType.NVarChar, 50)); myCMD. Parameters.Add (New SqlParameter ("@phonenumber", SqlDbType.NVarChar, 50)); myCMD. Parameters.Add (New SqlParameter ("@age", SqlDbType.Int)); myCMD. Parameters.Add (New SqlParameter ("@sex", SqlDbType.NChar, 10)); myCMD. Parameters.Add (New SqlParameter ("@vocation", SqlDbType.NVarChar, 50)); MycMd. parameters["@ID"]. Value = this.id. Text; myCMD. parameters["@name"]. Value = this. Name.text; myCMD. parameters["@address"]. Value = this. Address.text; myCMD. parameters["@phonenumber"]. Value = this. Phone.text; myCMD. parameters["@age"]. Value = this. Age.text; myCMD. parameters["@sex"]. Value = this. Sex.text; myCMD. parameters["@vocation"]. Value = this. Vacation.text; MyConn. Open (); myCMD. ExecuteNonQuery (); Reset all textbox this.id. Text = ""; This. Name.text = ""; This. Address.text = ""; This. Phone.text = ""; This. Age.text = ""; This. Sex.text = ""; This. Vacation.text = ""; Response.Write ("<script>alert (' has been added successfully, see Adding successful data ') </script>"); String sql2 = "SELECT * from"; SqlCommand newcmd = new SqlCommand (SQL2, myconn); SqlDataAdapter SDA = new SqlDataAdapter (Newcmd); DataSet ds = new DataSet (); Sda. Fill (ds, "Contact"); This. Gridview1.datasource = ds. tables["Contact"]; This. Gridview1.databind (); MyConn. Close (); }}
Other changes, such as the deletion of the same principle, refer to the above code.
Asp. NET additions and deletions to rewrite an address book system---Shinepans