⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 add_teacher.aspx.cs

📁 程序学生信息管理系统(SQL2000+ASP.NET+c#+)
💻 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;
using SMS;

public partial class Default2 : System.Web.UI.Page
{
    OPDataBase op = new OPDataBase();
   
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            for (int a = 1;a<=31; a++)
            {

                DropDownList4.Items.Add(new ListItem(a.ToString(), a.ToString()));



            }
            DropDownList4.SelectedIndex = 15;
            string sql = "select DepartmentID,Desn from Department ";
            SqlDataReader dr;
            dr =op .getDataReader (sql );
           while (dr .Read ())
           {
               DropDownList5.Items.Add(new ListItem(dr["Desn"].ToString(), dr["DepartmentID"].ToString()));

           }
        }
        Page.Dispose();
       
#region DropDownList5 控件绑定方法二。
        //连接数据库;
   //     string sqlstr = ConfigurationSettings.AppSettings["dsn"];
   //SqlConnection conn = new SqlConnection(sqlstr);
   //     //执行查询命令,并填充到数据阅读器里; 
   //if (!IsPostBack)
   //{
   //    conn.Open();
   //    SqlCommand cmd = new SqlCommand("select*from Department", conn);
   //    SqlDataReader dr;
   //    dr = cmd.ExecuteReader();
   //    //绑定到下拉列表;
   //    while (dr.Read())
   //    {
   //        this.DropDownList5.Items.Add(new ListItem(dr["Desn"].ToString(), dr["DepartmentID"].ToString()));

   //    }
   //    conn.Close();

   //}
#endregion
}

#region Button1_Click 事件。
protected void Button1_Click(object sender, EventArgs e)
    {
        string name, age, sex, address, hiredata, phone, departementID;
        name = TextBox1_name.Text.Trim();
        age = TextBox3_age.Text.Trim();
        sex = DropDownList1.SelectedValue.ToString();
        address = TextBox4_address.Text.Trim();
        hiredata = DropDownList2.SelectedValue.ToString() + DropDownList3.SelectedValue.ToString() + DropDownList4.SelectedValue.ToString();
        phone = TextBox5_phone.Text.Trim();
        departementID = DropDownList5.SelectedValue.ToString();
        SqlConnection conn = op.sqlConnection();
        conn.Open();
        string sql = "insert into Teacher(Name, Age, Sex, Address, HireDate,Phone,DepartmentID)values('"+
            name+"','"+age +"','"+sex+"','"+address+"','"+hiredata +"','"+phone+"','"+departementID+"')";
        SqlCommand cmd = new SqlCommand(sql,conn );
        if (TextBox1_name.Text != string.Empty || TextBox3_age.Text != string.Empty || TextBox5_phone.Text != string.Empty)
        {
            try
            {

                op.BindCommand(sql, Label1);
             
            }
            catch
            {
                Label1.Text = "*输入格式错误!*";
            
            }

        }
        else
        {
            string a = "*填写不能为空!*";
            Label1.Text = a;
        }
    }
# endregion
    protected void Button2_Click(object sender, EventArgs e)
    {
     
        TextBox1_name.Text = "";
        TextBox3_age.Text = "";
      
        TextBox5_phone.Text = "";
        Label1.Text = "";
       
    }

    
 
    }

⌨️ 快捷键说明

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