且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我想要SQL查询从一个表中检索数据并将其存储在另一个表中

更新时间:2022-12-11 23:04:04

SELECT *
INTO carcopy2 ////this is table where you will insert
FROM carcopy;/////this is from whre you are retrieving


protected void Button1_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection("connection string");
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from Users where UserID='"+Session["userid"].ToString()+"'",con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                SqlCommand cmd2 = new SqlCommand("insert into AppliedUsers values('" + dt.Rows[0][0].ToString() + "','" + dt.Rows[0][1].ToString() + "',......) ", con);
                cmd2.ExecuteNonQuery();
            }
            con.Close();
        }