📄 duzheguanli.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace mybook
{
/// <summary>
/// duzhecontrol 的摘要说明。
/// </summary>
public class duzhecontrol : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.TextBox TextBox4;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Button Button3;
protected System.Web.UI.WebControls.TextBox TextBox5;
protected System.Web.UI.WebControls.Button Button4;
protected System.Web.UI.WebControls.TextBox TextBox6;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.Label Label7;
protected System.Web.UI.WebControls.Label Label8;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Button Button6;
private void Page_Load(object sender, System.EventArgs e)
{
string strConn="server=.;uid=sa;pwd=sa;database=mybook";
SqlConnection myConnection=new SqlConnection();
myConnection.ConnectionString=strConn;
string strCommand="select * from duzhe";
SqlDataAdapter da=new SqlDataAdapter(strCommand,myConnection);
DataSet ds=new DataSet();
da.Fill(ds,"scores");
DataGrid1.DataSource=ds.Tables["scores"].DefaultView;
DataGrid1.DataBind();
myConnection.Close();// 在此处放置用户代码以初始化页面
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Button3.Click += new System.EventHandler(this.Button3_Click);
this.Button4.Click += new System.EventHandler(this.Button4_Click);
this.Button6.Click += new System.EventHandler(this.Button6_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = "uid=sa;pwd=sa;initial catalog=mybook;data source=.;Connect Timeout=90";
myConnection.Open();
string sql_Del = "DELETE FROM duzhe " +
" WHERE name= '" + e.Item.Cells[2].Text+"'";
//Response.Write(sql_Del);
SqlCommand sqlCommandDel = new SqlCommand(sql_Del,myConnection);
sqlCommandDel.ExecuteNonQuery();
myConnection.Close();
string mysql = "Select * FROM duzhe";
SqlDataAdapter myadaptor = new SqlDataAdapter(mysql,myConnection);
DataSet ds = new DataSet();
myadaptor.Fill(ds,"MyDataResult");
DataView myView = ds.Tables["MyDataResult"].DefaultView;
DataGrid1.DataSource=myView;
DataGrid1.DataBind();
}
private void Button1_Click(object sender, System.EventArgs e)
{
string strConn="server=.;uid=sa;pwd=sa;database=mybook";
SqlConnection myConnection=new SqlConnection();
myConnection.ConnectionString=strConn;
string strCommand="insert into duzhe values('"+TextBox6.Text+"','"+TextBox1.Text+"','"+TextBox2.Text+"','"+TextBox3.Text+"','"+TextBox4.Text+"')";
SqlCommand addScore=new SqlCommand(strCommand,myConnection);
myConnection.Open();
addScore.ExecuteNonQuery();
myConnection.Close();
}
private void Button2_Click(object sender, System.EventArgs e)
{
string strConn="server=.;uid=sa;pwd=sa;database=mybook";
SqlConnection myConnection=new SqlConnection();
myConnection.ConnectionString=strConn;
if(!IsPostBack)
{
DataGrid1.DataBind();
}
}
private void Button4_Click(object sender, System.EventArgs e)
{
string strConn="server=.;uid=sa;pwd=sa;database=mybook";
SqlConnection myConnection=new SqlConnection();
myConnection.ConnectionString=strConn;
string strCommand="delete from duzhe where name='"+TextBox5.Text+"'";
//Response.Write(strCommand);
SqlCommand addScore=new SqlCommand(strCommand,myConnection);
myConnection.Open();
addScore.ExecuteNonQuery();
myConnection.Close();
//DataGrid1.DataBind();
}
private void Button3_Click(object sender, System.EventArgs e)
{
Response.Redirect("adminlist.aspx");
}
private void Button6_Click(object sender, System.EventArgs e)
{
TextBox6.Text="";
TextBox1.Text="";
TextBox4.Text="";
TextBox2.Text="";
TextBox3.Text="";
TextBox5.Text="";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -