📄 adminstudentadd.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlConnection conn;
protected void Page_Load(object sender, EventArgs e)
{
string myconn=System .Configuration .ConfigurationManager .AppSettings ["ConnectionString"];
conn = new SqlConnection(myconn );
for (int i = 1999; i < 2020; i++)
{
ListItem lt = new ListItem(i.ToString(), i.ToString());
ddrutime.Items.Add(lt);
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
string sql = "insert into Student(stuID,stuName,stunation,stusex,stubirthday,stuClass,stuphone,stuGrade,stuPwd,stuDepart,stubeizhu) values('" + txtstuid.Text + "','" +txtstuname.Text + "','" +txtnation.Text + "','" +stusex.SelectedValue.ToString ()+ "','" +txtBirthday.Text + "','" +txtstuclass.Text + "','" +txtPhone.Text + "','" +ddrutime.SelectedValue .ToString () + "','" +txtPwd.Text + "','" +ddldepart .SelectedValue .ToString () + "','" +txtbeizhu.Text + "')";
SqlCommand insertCmd = new SqlCommand(sql, conn);
try
{
conn.Open();
int flag = insertCmd.ExecuteNonQuery();
if (flag > 0)
{
Label11.Visible = true;
Label11.Text = "成功添加学生信息!";
}
else
{
Label11.Visible = true;
Label11.Text = "添加学生信息失败,查看输入是否正确!";
}
}
catch (System.Exception ee)
{
Response.Write("<script language=javascript>alert('" + ee.Message.ToString() + "')</script>");
}
finally
{
conn.Close();
}
}
protected void btnBack_Click(object sender, EventArgs e)
{
txtstuid.Text = string.Empty ;
txtnation.Text = string .Empty ;
txtstuname.Text =string .Empty ;
txtstuclass.Text = string .Empty ;
txtPwd.Text = string .Empty ;
txtPhone .Text = string .Empty ;
txtBirthday .Text = string .Empty ;
txtbeizhu .Text = string .Empty ;
txtstuid.Focus();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -