📄 bjxx.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;
namespace tang
{
/// <summary>
/// bjxx 的摘要说明。
/// </summary>
public class bjxx : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected tang.DataSet1 dataSet11;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
protected System.Data.SqlClient.SqlConnection sqlConnection2;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)//页面第一次加载时;
{
if (Session["username"] ==null)
{
this.Response.Redirect("error.aspx");//重定向到登录也就是身份验证的那个页面
}
}
// 在此处放置用户代码以初始化页面
sqlDataAdapter1.Fill(dataSet11,"班级信息");
if(!Page.IsPostBack)
DataGrid1.DataBind();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection2 = new System.Data.SqlClient.SqlConnection();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
this.dataSet11 = new tang.DataSet1();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "班级信息", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("班级编号", "班级编号"),
new System.Data.Common.DataColumnMapping("辅导员", "辅导员"),
new System.Data.Common.DataColumnMapping("班级人数", "班级人数"),
new System.Data.Common.DataColumnMapping("专业名称", "专业名称")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = "DELETE FROM 班级信息 WHERE (班级编号 = @Original_班级编号) AND (专业名称 = @Original_专业名称 OR @Ori" +
"ginal_专业名称 IS NULL AND 专业名称 IS NULL) AND (班级人数 = @Original_班级人数 OR @Original_班级人" +
"数 IS NULL AND 班级人数 IS NULL) AND (辅导员 = @Original_辅导员 OR @Original_辅导员 IS NULL AN" +
"D 辅导员 IS NULL)";
this.sqlDeleteCommand1.Connection = this.sqlConnection2;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_班级编号", System.Data.SqlDbType.VarChar, 6, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "班级编号", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_专业名称", System.Data.SqlDbType.VarChar, 18, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "专业名称", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_班级人数", System.Data.SqlDbType.VarChar, 18, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "班级人数", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_辅导员", System.Data.SqlDbType.VarChar, 18, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "辅导员", System.Data.DataRowVersion.Original, null));
//
// sqlConnection2
//
this.sqlConnection2.ConnectionString = "workstation id=\"SUNLIGHT-17F324\";packet size=4096;integrated security=SSPI;data s" +
"ource=\"SUNLIGHT-17F324\";persist security info=False;initial catalog=大型数据库";
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO 班级信息(班级编号, 辅导员, 班级人数, 专业名称) VALUES (@班级编号, @辅导员, @班级人数, @专业名称); SELEC" +
"T 班级编号, 辅导员, 班级人数, 专业名称 FROM 班级信息 WHERE (班级编号 = @班级编号)";
this.sqlInsertCommand1.Connection = this.sqlConnection2;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@班级编号", System.Data.SqlDbType.VarChar, 6, "班级编号"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@辅导员", System.Data.SqlDbType.VarChar, 18, "辅导员"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@班级人数", System.Data.SqlDbType.VarChar, 18, "班级人数"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@专业名称", System.Data.SqlDbType.VarChar, 18, "专业名称"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT 班级编号, 辅导员, 班级人数, 专业名称 FROM 班级信息";
this.sqlSelectCommand1.Connection = this.sqlConnection2;
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE 班级信息 SET 班级编号 = @班级编号, 辅导员 = @辅导员, 班级人数 = @班级人数, 专业名称 = @专业名称 WHERE (班级编号 = @Original_班级编号) AND (专业名称 = @Original_专业名称 OR @Original_专业名称 IS NULL AND 专业名称 IS NULL) AND (班级人数 = @Original_班级人数 OR @Original_班级人数 IS NULL AND 班级人数 IS NULL) AND (辅导员 = @Original_辅导员 OR @Original_辅导员 IS NULL AND 辅导员 IS NULL); SELECT 班级编号, 辅导员, 班级人数, 专业名称 FROM 班级信息 WHERE (班级编号 = @班级编号)";
this.sqlUpdateCommand1.Connection = this.sqlConnection2;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@班级编号", System.Data.SqlDbType.VarChar, 6, "班级编号"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@辅导员", System.Data.SqlDbType.VarChar, 18, "辅导员"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@班级人数", System.Data.SqlDbType.VarChar, 18, "班级人数"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@专业名称", System.Data.SqlDbType.VarChar, 18, "专业名称"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_班级编号", System.Data.SqlDbType.VarChar, 6, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "班级编号", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_专业名称", System.Data.SqlDbType.VarChar, 18, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "专业名称", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_班级人数", System.Data.SqlDbType.VarChar, 18, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "班级人数", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_辅导员", System.Data.SqlDbType.VarChar, 18, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "辅导员", System.Data.DataRowVersion.Original, null));
//
// dataSet11
//
this.dataSet11.DataSetName = "DataSet1";
this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
}
#endregion
private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
public void DataGrid_Delete(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dataSet11.Tables["班级信息"].Rows[e.Item.DataSetIndex].Delete();
sqlDataAdapter1.Update(dataSet11,"班级信息");
DataGrid1.DataBind();
}
public void edit(object sourse,System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=e.Item.DataSetIndex;
DataGrid1.DataBind();
}
public void cancel(object sourse,System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=-1;
DataGrid1.DataBind();
}
public void updata(object sourse,System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dataSet11.Tables["班级信息"].Rows[e.Item.DataSetIndex]["班级编号"]=((TextBox)e.Item.Cells[0].Controls[0]).Text;
dataSet11.Tables["班级信息"].Rows[e.Item.DataSetIndex]["专业编号"]=((TextBox)e.Item.Cells[1].Controls[0]).Text;
dataSet11.Tables["班级信息"].Rows[e.Item.DataSetIndex]["辅导员"]=((TextBox)e.Item.Cells[2].Controls[0]).Text;
dataSet11.Tables["班级信息"].Rows[e.Item.DataSetIndex]["班级人数"]=((TextBox)e.Item.Cells[3].Controls[0]).Text;
sqlDataAdapter1.Update(dataSet11,"班级信息");
DataGrid1.EditItemIndex=-1;
DataGrid1.DataBind();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -