📄 manageciceroni.aspx.cs
字号:
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@sex", System.Data.SqlDbType.VarChar, 10, "sex"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@age", System.Data.SqlDbType.Int, 4, "age"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@picture", System.Data.SqlDbType.VarChar, 50, "picture"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@telephone", System.Data.SqlDbType.VarChar, 50, "telephone"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param1", System.Data.SqlDbType.VarChar, 50, "level"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT ciceroniid, name, sex, age, picture, telephone, [level] FROM ciceroni";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE ciceroni SET ciceroniid = @ciceroniid, name = @name, sex = @sex, age = @age, picture = @picture, telephone = @telephone, [level] = @Param2 WHERE (ciceroniid = @Original_ciceroniid) AND (age = @Original_age OR @Original_age IS NULL AND age IS NULL) AND ([level] = @Original_level OR @Original_level IS NULL AND [level] IS NULL) AND (name = @Original_name) AND (picture = @Original_picture OR @Original_picture IS NULL AND picture IS NULL) AND (sex = @Original_sex) AND (telephone = @Original_telephone OR @Original_telephone IS NULL AND telephone IS NULL); SELECT ciceroniid, name, sex, age, picture, telephone, [level] FROM ciceroni WHERE (ciceroniid = @ciceroniid)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ciceroniid", System.Data.SqlDbType.Int, 4, "ciceroniid"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@name", System.Data.SqlDbType.VarChar, 50, "name"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@sex", System.Data.SqlDbType.VarChar, 10, "sex"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@age", System.Data.SqlDbType.Int, 4, "age"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@picture", System.Data.SqlDbType.VarChar, 50, "picture"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@telephone", System.Data.SqlDbType.VarChar, 50, "telephone"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param2", System.Data.SqlDbType.VarChar, 50, "level"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ciceroniid", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ciceroniid", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_age", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "age", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_level", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "level", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_name", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "name", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_picture", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "picture", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_sex", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "sex", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_telephone", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "telephone", System.Data.DataRowVersion.Original, null));
//
// dataSet61
//
this.dataSet61.DataSetName = "DataSet6";
this.dataSet61.Locale = new System.Globalization.CultureInfo("zh-CN");
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet61)).EndInit();
}
#endregion
private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.DataGrid1.EditItemIndex=-1;
bindData();
}
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
int ciceroniid=Convert.ToInt32(this.DataGrid1.DataKeys[e.Item.ItemIndex].ToString());
SqlConnection con=DB.createCon();
SqlCommand cmd=new SqlCommand("delete from ciceroni where ciceroniid='"+ciceroniid+"'",con);
con.Open();
cmd.ExecuteNonQuery();
this.bindData();
}
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=e.Item.ItemIndex;
bindData();
}
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
{
((LinkButton)(e.Item.Cells[7].Controls[0])).Attributes.Add("onclick","return confirm('确认要删除吗?');");
((LinkButton)(e.Item.Cells[8].Controls[0])).Attributes.Add("onclick","return confirm('确认要修改吗?');");
}
}
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
SqlConnection con =DB.createCon();
con.Open ();
int ciceroniid= Convert.ToInt32(this.DataGrid1.DataKeys[e.Item.ItemIndex].ToString());
//非只读绑定列,处于编辑状态
string name = ((TextBox)(e.Item.Cells[1].Controls[0])).Text;
string sex= ((TextBox)(e.Item.Cells[2].Controls[0])).Text;
string age= ((TextBox)(e.Item.Cells[3].Controls[0])).Text;
string picture= ((TextBox)(e.Item.Cells[4].Controls[0])).Text;
string telephone= ((TextBox)(e.Item.Cells[5].Controls[0])).Text;
string level= ((TextBox)(e.Item.Cells[6].Controls[0])).Text;
// this.Response.Write(readersex);
string strSql = "update ciceroni set name = '"+name+"',sex='"+sex+"',age='"+age+"',picture='"+picture+"',telephone='"+telephone+"',level='"+level+"'where ciceroniid =" +ciceroniid ;
// string strSql = "update 读者信息表 set readername = '" + readername + "',readsex='"+readersex+"',readerdep='"+readerdep+"',readertype='"+readertype+"'where readerid =" + readerid;
SqlCommand cmd=new SqlCommand (strSql,con);
try
{
cmd.ExecuteNonQuery();
this.Response.Write(" <script language ='javascript'> alert ('更新成功!')</script>");
this.DataGrid1.EditItemIndex=-1; //退出行的编辑模式
}
catch
{
this.Response.Write(" <script language ='javascript'> alert ('更新失败!')</script>");
}
this.DataGrid1.EditItemIndex=-1;
bindData();
}
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.DataGrid1.CurrentPageIndex=e.NewPageIndex;
this.bindData();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -