As the title says, I need help for my website. I need to copy a certain data from a table and put it on the other table. I tried to use the all kinds of languages / procedures but it still doesn't work.
Here's my code:
[HttpPost, ActionName("AddSubjects")]
[ValidateAntiForgeryToken]
public ActionResult AddSubjectConfirm(string s)
{
DataTable dr = new DataTable();
SqlDataAdapter dat = new SqlDataAdapter();
SqlConnection con = new SqlConnection(@"data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=|DataDirectory|\UESLDB.mdf;");
string qu = "INSERT INTO EnrolledSubjects (SubjectCode, SubjectDescription) SELECT SubjectCode, SubjectDescription FROM Subjects WHERE SubjectCode = '" + s + "'";
con.Open();
SqlCommand cmd = new SqlCommand(qu, con);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
con.Close();
return View("Home");
}
A student needs to add a subject (which is already on the database for subjects) then the subject code of the subject will be stored in the "string s" and the controller will find the subject with similar subject code and then it will get the subjectcode and description and insert it to another table.
The thing is I don't know what's wrong. If somebody can help me I will be truly grateful.
Sorry for my bad explanation I'm a newbie.