Mysql odbc插入参数

本文关键字:参数 插入 odbc Mysql | 更新日期: 2023-09-27 17:48:56

谁能告诉我为什么我只得到flag插入到我的表,而不是一切?

using (var conn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite2; User=root; Password=commando;"))
{
    conn.Open();
    {
        using (var cmd = conn.CreateCommand())
        {
            cmd.CommandText = "INSERT INTO User (Email, FirstName, SecondName, DOB, Location, Aboutme, username, password, flag) VALUES (@Email, @FirstName, @SecondName, @DOB, @Location, @Aboutme, @username, @password, 1)";
            cmd.Parameters.AddWithValue("@Email", TextBox1.Text);
            cmd.Parameters.AddWithValue("@FirstName", TextBox2.Text);
            cmd.Parameters.AddWithValue("@SecondName", TextBox3.Text);
            // TODO: might require a parsing if the column is of type date in SQL
            cmd.Parameters.AddWithValue("@DOB", TextBox4.Text);
            cmd.Parameters.AddWithValue("@Location", TextBox5.Text);
            cmd.Parameters.AddWithValue("@Aboutme", TextBox6.Text);
            cmd.Parameters.AddWithValue("@username", TextBox7.Text);
            cmd.Parameters.AddWithValue("@password", TextBox8.Text);
            cmd.ExecuteNonQuery();
        }
        Response.Redirect("Uploadpicture.aspx");
    }
}

Mysql odbc插入参数

您必须使用问号作为参数占位符,并按正确的顺序添加它们。

类似的问题:MySQL拒绝参数