new_profession.aspx.cs

来自「本套软件适用于各大高校、中小学、幼儿园、培训机构等单位的教学管理软件。」· CS 代码 · 共 53 行

CS
53
字号
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;
using jianke;
public partial class new_profession : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {  if(!IsPostBack)
        Dept_Bind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection Conn = DB.creatconnection();
        Conn.Open();

        string str = "insert into Profession(dept_id,profession_name)values("+this.DropDownList1.SelectedValue+",'" + this.TextBox1.Text + "')";
        SqlCommand cmd = new SqlCommand(str, Conn);
        cmd.ExecuteNonQuery();
        Conn.Close();
        Response.Write("<script>alert('录入成功!');</script>");
        this.TextBox1.Text = "";


    }
    public void Dept_Bind()
    {
        SqlConnection Conn = DB.creatconnection();
        Conn.Open();
        SqlCommand cmd = new SqlCommand("select  dept_name,dept_id from Dept", Conn);

        SqlDataReader sdr = cmd.ExecuteReader();
        this.DropDownList1.DataSource = sdr;
        this.DropDownList1.DataTextField = "dept_name";
        this.DropDownList1.DataValueField = "dept_id";
        this.DropDownList1.DataBind();

        sdr.Close();
        Conn.Close();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        this.TextBox1.Text = "";
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?