📄 studentedit.aspx.cs
字号:
"mail, Student_LiveCost, Student_StudyCost, Student_Address, Student_Phone FROM S" +
"tudent";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = "UPDATE Student SET Student_ID = @Student_ID, Student_Name = @Student_Name, Studen" +
"t_Password = @Student_Password, Student_Birth = @Student_Birth, Student_Sex = @S" +
"tudent_Sex, Student_Photo = @Student_Photo, Student_Depart = @Student_Depart, St" +
"udent_Course = @Student_Course, Student_Postion = @Student_Postion, Room_ID = @R" +
"oom_ID, Student_Email = @Student_Email, Student_LiveCost = @Student_LiveCost, St" +
"udent_StudyCost = @Student_StudyCost, Student_Address = @Student_Address, Studen" +
"t_Phone = @Student_Phone WHERE (Student_ID = @Original_Student_ID) AND (Room_ID " +
"= @Original_Room_ID OR @Original_Room_ID IS NULL AND Room_ID IS NULL) AND (Stude" +
"nt_Address = @Original_Student_Address OR @Original_Student_Address IS NULL AND " +
"Student_Address IS NULL) AND (Student_Birth = @Original_Student_Birth OR @Origin" +
"al_Student_Birth IS NULL AND Student_Birth IS NULL) AND (Student_Course = @Origi" +
"nal_Student_Course) AND (Student_Depart = @Original_Student_Depart) AND (Student" +
"_Email = @Original_Student_Email OR @Original_Student_Email IS NULL AND Student_" +
"Email IS NULL) AND (Student_LiveCost = @Original_Student_LiveCost OR @Original_S" +
"tudent_LiveCost IS NULL AND Student_LiveCost IS NULL) AND (Student_Name = @Origi" +
"nal_Student_Name) AND (Student_Password = @Original_Student_Password OR @Origina" +
"l_Student_Password IS NULL AND Student_Password IS NULL) AND (Student_Phone = @O" +
"riginal_Student_Phone OR @Original_Student_Phone IS NULL AND Student_Phone IS NU" +
"LL) AND (Student_Photo = @Original_Student_Photo OR @Original_Student_Photo IS N" +
"ULL AND Student_Photo IS NULL) AND (Student_Postion = @Original_Student_Postion " +
"OR @Original_Student_Postion IS NULL AND Student_Postion IS NULL) AND (Student_S" +
"ex = @Original_Student_Sex) AND (Student_StudyCost = @Original_Student_StudyCost" +
" OR @Original_Student_StudyCost IS NULL AND Student_StudyCost IS NULL); SELECT S" +
"tudent_ID, Student_Name, Student_Password, Student_Birth, Student_Sex, Student_P" +
"hoto, Student_Depart, Student_Course, Student_Postion, Room_ID, Student_Email, S" +
"tudent_LiveCost, Student_StudyCost, Student_Address, Student_Phone FROM Student " +
"WHERE (Student_ID = @Student_ID)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Student_ID", System.Data.SqlDbType.BigInt, 8, "Student_ID"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Student_Name", System.Data.SqlDbType.VarChar, 8, "Student_Name"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Student_Password", System.Data.SqlDbType.VarChar, 16, "Student_Password"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Student_Birth", System.Data.SqlDbType.NVarChar, 10, "Student_Birth"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Student_Sex", System.Data.SqlDbType.VarChar, 2, "Student_Sex"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Student_Photo", System.Data.SqlDbType.VarChar, 30, "Student_Photo"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Student_Depart", System.Data.SqlDbType.VarChar, 20, "Student_Depart"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Student_Course", System.Data.SqlDbType.VarChar, 20, "Student_Course"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Student_Postion", System.Data.SqlDbType.VarChar, 20, "Student_Postion"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Room_ID", System.Data.SqlDbType.BigInt, 8, "Room_ID"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Student_Email", System.Data.SqlDbType.VarChar, 30, "Student_Email"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Student_LiveCost", System.Data.SqlDbType.Money, 8, "Student_LiveCost"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Student_StudyCost", System.Data.SqlDbType.Money, 8, "Student_StudyCost"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Student_Address", System.Data.SqlDbType.VarChar, 50, "Student_Address"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Student_Phone", System.Data.SqlDbType.VarChar, 12, "Student_Phone"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Student_ID", System.Data.SqlDbType.BigInt, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Student_ID", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Room_ID", System.Data.SqlDbType.BigInt, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Room_ID", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Student_Address", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Student_Address", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Student_Birth", System.Data.SqlDbType.NVarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Student_Birth", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Student_Course", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Student_Course", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Student_Depart", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Student_Depart", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Student_Email", System.Data.SqlDbType.VarChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Student_Email", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Student_LiveCost", System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Student_LiveCost", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Student_Name", System.Data.SqlDbType.VarChar, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Student_Name", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Student_Password", System.Data.SqlDbType.VarChar, 16, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Student_Password", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Student_Phone", System.Data.SqlDbType.VarChar, 12, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Student_Phone", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Student_Photo", System.Data.SqlDbType.VarChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Student_Photo", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Student_Postion", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Student_Postion", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Student_Sex", System.Data.SqlDbType.VarChar, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Student_Sex", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Student_StudyCost", System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Student_StudyCost", System.Data.DataRowVersion.Original, null));
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.DataGrid1.EditItemIndex=e.Item.ItemIndex;
if(this.TextBox4.Text!="")
Grid_Bind();
else if(this.TextBox4.Text=="")
Data_Bind();
}
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
try
{
myConn=ConfigurationSettings.AppSettings["mySql"];
string cmdstr="update Student set Student_Name='"+((TextBox)e.Item.Cells[1].Controls[0]).Text+"',Student_Depart='"+((TextBox)e.Item.Cells[3].Controls[0]).Text+"',Student_Course='"+((TextBox)e.Item.Cells[4].Controls[0]).Text+"',Student_Birth='"+((TextBox)e.Item.Cells[5].Controls[0]).Text+"',Student_Postion='"+((TextBox)e.Item.Cells[6].Controls[0]).Text+"',Student_Email='"+((TextBox)e.Item.Cells[8].Controls[0]).Text+"',Student_Address='"+((TextBox)e.Item.Cells[9].Controls[0]).Text+"',Student_Phone='"+((TextBox)e.Item.Cells[10].Controls[0]).Text+"'where Student_ID='"+e.Item.Cells[0].Text+"'";
conn=new SqlConnection(myConn);
conn.Open();
cmd=new SqlCommand(cmdstr,conn);
cmd.ExecuteNonQuery();
conn.Close();
this.DataGrid1.EditItemIndex=-1;
if(this.TextBox4.Text!="")
Grid_Bind();
else if(this.TextBox4.Text=="")
Data_Bind();
}
catch(Exception ex)
{
Response.Write("<script>alert('"+ex.Message+"输入数据格式错误!')</script>");
}
}
private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.DataGrid1.EditItemIndex=-1;
if(this.TextBox4.Text!="")
Grid_Bind();
else if(this.TextBox4.Text=="")
Data_Bind();
}
private void Button1_Click(object sender, System.EventArgs e)
{
this.DataGrid1.CurrentPageIndex=0;
string s;
s=this.DropDownList1.SelectedValue.ToString()+"="+"'"+this.TextBox4.Text+"'";
this.myConn=ConfigurationSettings.AppSettings["mySql"];
this.conn=new System.Data.SqlClient.SqlConnection(myConn);
try
{
if(this.TextBox4.Text!="")
{
cmdText="select * from Student where ";
cmdText=cmdText+s;
this.sqlConnection1=new System.Data.SqlClient.SqlConnection(myConn);
this.sqlConnection1.Open();
this.sqlDataAdapter1=new System.Data.SqlClient.SqlDataAdapter(cmdText,this.sqlConnection1);
this.dataSet11=new DataSet1();
this.sqlDataAdapter1.Fill(this.dataSet11,"Student");
this.DataGrid1.DataSource=this.dataSet11;
this.DataGrid1.DataBind();
this.sqlConnection1.Close();
}
else
{
Response.Write("<script>alert('请输入查询条件!')</script>");
Data_Bind();}
}
catch(Exception ex)
{
Response.Write("<script>alert('"+ex.Message+"查询条件格式错误!')</script>");
}
}
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
if(this.TextBox4.Text!="")
Grid_Bind();
else if(this.TextBox4.Text=="")
Data_Bind();
}
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.EditItem)
{
//((TextBox)e.Item.Cells[0].Controls[0]).Width = Unit.Pixel(50);
((TextBox)e.Item.Cells[1].Controls[0]).Width = Unit.Pixel(50);
//((TextBox)e.Item.Cells[2].Controls[0]).Width = Unit.Pixel(50);
((TextBox)e.Item.Cells[3].Controls[0]).Width = Unit.Pixel(50);
((TextBox)e.Item.Cells[4].Controls[0]).Width = Unit.Pixel(50);
((TextBox)e.Item.Cells[5].Controls[0]).Width = Unit.Pixel(50);
((TextBox)e.Item.Cells[6].Controls[0]).Width = Unit.Pixel(50);
// ((TextBox)e.Item.Cells[7].Controls[0]).Width = Unit.Pixel(60);
((TextBox)e.Item.Cells[8].Controls[0]).Width = Unit.Pixel(50);
((TextBox)e.Item.Cells[9].Controls[0]).Width = Unit.Pixel(60);
((TextBox)e.Item.Cells[10].Controls[0]).Width = Unit.Pixel(60);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -