开发者

mysql odbc insert with params

开发者 https://www.devze.com 2023-02-22 08:29 出处:网络
can any one tell me why im only getting flag inserted into my tables rather than everything? using (var conn = new OdbcConnection(\"Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebs

can any one tell me why im only getting flag inserted into my tables rather than everything?

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");
    }
}


You have to use question marks for parameter place holders and add them in the correct order.

Similar question here: MySQL rejecting parameter

0

精彩评论

暂无评论...
验证码 换一张
取 消