表1表2中的记录插入表3中

来源:互联网 发布:鞋子淘宝店 编辑:程序博客网 时间:2024/06/01 10:10

    protected void btnOk_Click1(object sender, EventArgs e)
    {
         string strCon = ConfigurationManager.ConnectionStrings["TPVConnectionString"].ToString();
        SqlConnection con = new SqlConnection(strCon);
        con.Open();
        string strSql = "select * from[USER] where [LOGONID]='"+txtAD.Text.Trim()+"'";
        SqlCommand com = new SqlCommand(strSql,con);
        SqlDataReader dr = com.ExecuteReader();

        if(dr.Read())
        {
             string strconn = ConfigurationManager.ConnectionStrings["TPVConnectionString"].ToString();
             SqlConnection conn = new SqlConnection(strconn);
             conn.Open();
             lblName.Text=dr["USERNAME"].ToString();
             lblName.Visible = true;
             string strSqlInsert = @"insert into [GROUPUSER](USERID,GROUPID) select [USER].USERID , [GROUP].GROUPID from [USER],[GROUP]

                   where GROUPNAME='"+ddlGroup.SelectedValue+"' and USERNAME='"+lblName.Text+"'";
             SqlCommand comm = new SqlCommand(strSqlInsert,conn);
             comm.ExecuteNonQuery();
             conn.Close();
             Response.Write("<script>alert('添加权限成功!');</script>");


        }
        else
        {
            lblName.Text = "不存在此AD!";
            lblName.Visible = true;
            btnOk.Enabled = false;

        }
        con.Close();
    }

 

   

原创粉丝点击