I made such a construction, to add data to the database, the question, was the query written correctly, and if it is taken into account that this is a cycle, would such a solution be effective?
using (SqlConnection connection =new SqlConnection(connextionstring)) { SqlCommand command =new SqlCommand("DELETE FROM Class1", connection); connection.Open(); command.ExecuteNonQuery(); SqlCommand command2 = new SqlCommand("DELETE FROM Class2", connection); command2.ExecuteNonQuery(); SqlCommand command3 = new SqlCommand("DELETE FROM Class3", connection); command3.ExecuteNonQuery(); SqlCommand command4 = new SqlCommand("DELETE FROM Class4", connection); command4.ExecuteNonQuery(); SqlCommand command5 = new SqlCommand("DELETE FROM Class5", connection); command5.ExecuteNonQuery(); Class1 contactMary = ObjectSpace.FindObject<Class1>(); foreach (var VARIABLE in mass2) { String[] words = VARIABLE.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); var a= contactMary.METHODID = Convert.ToInt16(words[0]); var b= contactMary.DESCRIPTION = words[1]; var c= contactMary.METHODTYPEID = words[2]; var d= contactMary.TEXTDESCRIPTION = words[3]; SqlCommand command6 = new SqlCommand("INSERT INTO Class1 (METHODID, DESCRIPTION, METHODTYPEID, TEXTDESCRIPTION) VALUES (@a, @b, @c, @d)", connection); command6.Parameters.AddWithValue("@a",a); command6.Parameters.AddWithValue("@b",b); command6.Parameters.AddWithValue("@c",c); command6.Parameters.AddWithValue("@d",d); command6.ExecuteNonQuery(); }
... SET METHODID="a", DESCRI...instead ofashould substitute the value of the variable, and even correctly frame it with quotes? And I’ll guess that in the fragment... INTO Class1 SET ...you don’t need to do this ... I’m sorry - you’ll have to do it yourself. - Akina