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

📄 default.aspx.cs

📁 这是asp.net^和Visual C++Sharp编写的串并口通讯的书籍 源代码
💻 CS
字号:
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
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SqlConnection con = new SqlConnection("Server=(local);database=mrdb;Uid=sa;Pwd=");
            con.Open();
            SqlCommand com = new SqlCommand("select * from 部门工资统计表 select * from 明细工资表", con);
            SqlDataReader dr = com.ExecuteReader();
            while (dr.Read())
            {
                DropDownList1.Items.Add(dr[3].ToString());
            }
            dr.Close();
            con.Close();
            Bind();
        }  
    }
    private void Bind()
    {
        
            SqlConnection con = new SqlConnection("Server=(local);database=mrdb;Uid=sa;Pwd=");
            con.Open();
            SqlDataAdapter dap = new SqlDataAdapter("select * from 部门工资统计表 select * from 明细工资表", con);
            DataSet ds = new DataSet();
            dap.Fill(ds, "table");
            GridView1.DataSource = ds.Tables[0].DefaultView;
            GridView1.DataBind();
            GridView2.DataSource = ds.Tables[1].DefaultView;
            GridView2.DataBind();
        
       
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedValue.ToString()!="请选择")
        {
            SqlConnection con = new SqlConnection("Server=(local);database=mrdb;Uid=sa;Pwd=");
            SqlCommand cmd = new SqlCommand("update 部门工资统计表 set 基本工资=" + Convert.ToDecimal(TextBox1.Text) + "where 员工姓名 = '" + DropDownList1.SelectedValue + "'", con);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
            Bind();
            Response.Write("<script>alert('修改成功!');location='Default.aspx'</script>");
        }
        else
        {
            Response.Write("<script>alert('更新的数据不能为空!');location='Default.aspx'</script>");
        }

    }
    protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView2.PageIndex = e.NewPageIndex;
        GridView2.DataBind();
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("server=(local);user id=sa;pwd=;DataBase=mrdb");
        try
        {
            if (DropDownList1.SelectedValue.ToString() != null)
            {
                con.Open();
                string cmdtxt = "select * from 部门工资统计表 where 员工姓名='" + DropDownList1.SelectedValue + "'";
                SqlCommand mycom = new SqlCommand(cmdtxt, con);
                SqlDataReader dr = mycom.ExecuteReader();
                while (dr.Read())
                {
                    TextBox1.Text = dr["基本工资"].ToString();
                }
                dr.Close();
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message.ToString());
        }
        finally
        {
            con.Close();
        }
    }
}
   

 
           

⌨️ 快捷键说明

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