updata.aspx.cs

来自「水晶报表详细资料水晶报表详细资料水晶报表详细资料」· CS 代码 · 共 93 行

CS
93
字号
using System;
using System.Data;
using System.Configuration;
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 myConn;
    SqlDataAdapter adapter;
    DataSet ds;
    SqlCommand myCmd;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetDataInfo();
        }
    }
    protected SqlConnection GetConnectionString()
    {
        return (new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString()));
    }
    protected void GetDataInfo()
    {
        try
        {
            myConn = GetConnectionString();
            string strSql = "select * from tb_Student where 学生编号=" + Request.QueryString["id"].ToString();
            adapter = new SqlDataAdapter(strSql, myConn);
            ds = new DataSet();
            adapter.Fill(ds);
            this.txtID.Text = Request.QueryString["id"].ToString();
            this.txtName.Text = ds.Tables[0].Rows[0]["学生姓名"].ToString();
            this.ddlSex.SelectedValue = ds.Tables[0].Rows[0]["学生性别"].ToString();
            this.txtBirthday.Text = Convert.ToDateTime(ds.Tables[0].Rows[0]["出生年月"].ToString()).ToShortDateString();
            this.txtHAddress.Text = ds.Tables[0].Rows[0]["家庭住址"].ToString();
            this.txtTel.Text = ds.Tables[0].Rows[0]["家庭电话"].ToString();
        }
        catch(Exception ex)
        {
            Response.Write(ex.ToString());
        }
        finally
        {
            myConn.Dispose();
            adapter.Dispose();
            ds.Dispose();
        }  
    }
    protected void btnReg_Click(object sender, EventArgs e)
    {
        try
        {
            myConn = GetConnectionString();
            string strSql = " update tb_student set 学生姓名='" + this.txtName.Text.Trim() + "',学生性别='" + this.ddlSex.SelectedValue.ToString() + "',出生年月='" + this.txtBirthday.Text.Trim() + "',家庭住址='" + this.txtHAddress.Text.Trim() + "',家庭电话='" + this.txtTel.Text.Trim() + "'";
            strSql += " where 学生编号='"+Request.QueryString["id"].ToString()+"'";
            myCmd = new SqlCommand(strSql,myConn);
            myConn.Open();
            myCmd.ExecuteNonQuery();
            Response.Write("<script>alert('修改成功!');location='Default.aspx';</script>");
        }
        catch(Exception ex)
        {
            Response.Write(ex.ToString());
        }
        finally
        {
            myConn.Close();
            myCmd.Dispose();
        }  
    }
    protected void calDate_SelectionChanged(object sender, EventArgs e)
    {
        this.txtBirthday.Text = this.calDate.SelectedDate.ToShortDateString();
        this.calDate.Visible = false;
    }
    protected void btnSelDate_Click(object sender, EventArgs e)
    {
        calDate.Visible = true;

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }
}

⌨️ 快捷键说明

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