非查询c语法错误#

6bc51xsx  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(380)

对于学校,我需要用c和mysql制作一个web应用程序。在应用程序中有一个注册页,但是当我点击按钮完成时,我得到一个语法错误,它说execute.nonquery是错误的。有人能帮我吗?
代码如下:

MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["gpopdrachtConnectionString"].ConnectionString);

            string insertQ;
            insertQ = "Insert into tblWerknemer(Gebruikersnaam, Vnaam, Fnaam, Wachtwoord, Geboortedatum, Geboorteplaats, E-mailadres, Geslacht, Loon, gsmNummer, Nationaliteit, Gemeente, Postcode, StraatEnNr)";
            insertQ += "values(@gbr, @Vn, @Fn, @Ww, @GebD, @GebPl, @Email, @Geslacht, @Loon, @gsm, @Nat, @Gemeent, @Post, @Strtnr)";
            insertQ += "Insert into tbldiploma(school,NaamDiploma) Values(@school,@diploma)";
            insertQ += "Insert into tblpostcode(postcode,gemeente) Values(@Post,@Gemeent)";
            insertQ += "Insert into tblstatuut(omschrijving) Values(@omschrijving)";

            MySqlCommand cmd = new MySqlCommand();
            //= new MySqlCommand(insertQ, conn); 

            cmd.CommandText = insertQ;
            cmd.Connection = conn;
            cmd.Parameters.AddWithValue("@gbr", txtgbr.Text);
            cmd.Parameters.AddWithValue("@Vn", txtVnaam.Text);
            cmd.Parameters.AddWithValue("@Fn", txtfnaam.Text);
            cmd.Parameters.AddWithValue("@Ww", txtww.Text);
            cmd.Parameters.AddWithValue("@GebD", txtgdatum.Text);
            cmd.Parameters.AddWithValue("@GebPl", txtgplaats.Text);
            cmd.Parameters.AddWithValue("@Email", txtemail.Text);
            cmd.Parameters.AddWithValue("@Geslacht", checkgeslacht.SelectedItem.ToString());
            cmd.Parameters.AddWithValue("@diploma", txtdiploma.Text);
            cmd.Parameters.AddWithValue("@school", txtschool.Text);
            cmd.Parameters.AddWithValue("@Loon", txtloon.Text);
            cmd.Parameters.AddWithValue("@omschrijving", txtstatuut.Text);
            cmd.Parameters.AddWithValue("@gsm", txtgsm.Text);
            cmd.Parameters.AddWithValue("@Nat", txtnat.Text);
            cmd.Parameters.AddWithValue("@Gemeent", txtgemeent.Text);
            cmd.Parameters.AddWithValue("@Post", txtpost.Text);
            cmd.Parameters.AddWithValue("@Strtnr", txtstrt.Text);

            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();

这就是错误:
mysql.data.mysqlclient.mysqlexception:'您的sql语法有错误;查看与您的mysql服务器版本相对应的手册,以获得正确的语法来使用near'-mailadres,geslacht,loon,gsmnummer,nationateit,gemeente,postcode,straat'at line 1'

drnojrws

drnojrws1#

你的问题是emailadres附近的语法(你写它的方式),试着把它改成emailaddres或email\u-adres这样的名字。破折号(-)会给你带来麻烦

相关问题