I have a little problem to insert from 2 different table's in C# to MySql database
Here is my code where the error occurs
command.CommandText =
@"INSERT INTO personen (Name, Surname, GenderID, BirthplaceID)
VALUE @Name, @Surname, (SELECT GenderID FROM gender WHERE Gender = @GenderID),
(SELECT BirthplaceID FROM place WHERE placename = @BirthplaceID);";
When I replace the "@" statements and just fill in the name's, it works properly. So I want to know where the problem is.
Also the problem ain't the parameters like some answers said, cause i've added them(see below).
insertname = data.Name;
insertsurname = data.Surname;
insertgenderid= data.Gender;
insertbirthplaceid= data.Birthplace;
command.Parameters.AddWithValue("@Name", insertname);
command.Parameters.AddWithValue("@Surname", insertsurname);
command.Parameters.AddWithValue("@GenderID", insertgenderid);
command.Parameters.AddWithValue("@BirthplaceID", insertbirthplaceid);
command.ExecuteNonQuery();