I want to be able to duplicate data in a table if i have similar conditions for two activities. Example, I have an "Reparator E" and "Reparator E principal" with similar activities. I already populated the table for Reparator E and I want to copy data but replace the id for Reparator E principal. What I tried is
protected void AddActivitateRisc() { using (SqlConnection conn = new SqlConnection(connString)) { string sqlQuery = "INSERT INTO tblEvaris (Componenta,FactorRisc,FormaManifestare,Gravitate,ClsGravitate,Probabilitate,ClsProbabilitate,Risc,AID) SELECT (Componenta,FactorRisc,FormaManifestare,Gravitate,ClsGravitate,Probabilitate,ClsProbabilitate,Risc,@AIDNew) FROM tblEvaris WHERE AID = @AID"; using (SqlCommand cmd = new SqlCommand(sqlQuery, conn)) { cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@AID", ddlAN.SelectedItem.Value); cmd.Parameters.AddWithValue("@AIDNew", txtAD.Text); conn.Open(); int result = cmd.ExecuteNonQuery(); if (result > 0) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Record Inserted Successfully')", true); } conn.Close(); Session["AID"] = txtAD.Text; txtAD.Text = string.Empty; } } GetActivitateAll(); }
but there is something wrong with sqlQuery and I have an error. Parameters are correct, already checked that