admin/edit_st.aspx.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace 作业.admin
{
    public partial class edit_st : System.Web.UI.Page
    {
        static string connstr = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];//定义静态链接数据库参数
        SqlConnection Conn = new SqlConnection(connstr);//定义连接SQL数据库连接对象conn
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind();
            }
        }
        //
        public void bind()
        {
            //以下代码绑定班级
            string query = "select * from bj";
            SqlCommand cmd = new SqlCommand(query, Conn);//创建一个command对象,装载的参数分别是SQL语句和一个连接对象Conn
            SqlDataAdapter da = new SqlDataAdapter();//建立一个数据连接器
            da.SelectCommand = cmd;//da的选择COMMAND对象是cmd
            DataSet ds = new DataSet();//建立一个dataset
            da.Fill(ds, "bj");//数据适配器向ds中装载表depart
            DataTable d1 = ds.Tables["bj"];//建立一个datatable对象dt,他的实例是da中的表dapart;
            this.ddl_bj.DataSource = d1;
            this.ddl_bj.DataTextField = "bj";
            this.ddl_bj.DataValueField = "bj_id";
            this.ddl_bj.DataBind();
            
            int id = Convert.ToInt32(Request.QueryString["id"].ToString());
            string cx = "select * from student where stu_id=" + id;
            SqlCommand cmd3 = new SqlCommand(cx, Conn);//创建一个command对象,装载的参数分别是SQL语句和一个连接对象Conn
            da.SelectCommand = cmd3;//da的选择COMMAND对象是cmd
            da.Fill(ds, "st");//数据适配器向ds中装载表tea
            DataTable dts = ds.Tables["st"];
            this.txt_zh.Text = dts.Rows[0]["xh"].ToString();
            this.txt_mima.Text = dts.Rows[0]["mima"].ToString();
            this.txt_name.Text = dts.Rows[0]["name"].ToString();
            this.ddl_bj.Items.FindByValue(dts.Rows[0]["bj_id"].ToString()).Selected = true;
            
            //
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(Request.QueryString["id"].ToString());
            int bj_id = int.Parse(this.ddl_bj.SelectedValue.ToString());
            string zh = this.txt_zh.Text.ToString();
            string mima = this.txt_mima.Text.ToString();
            string name = this.txt_name.Text.ToString();
            string sex = this.rbt_sex.SelectedValue.ToString();
            string sql = "update student set bj_id='" + bj_id + "',xh='" + zh + "',mima='" + mima + "',name='" + name + "',sex='" + sex + "' where stu_id=" + id;
后面还有 11 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。