gpt4 book ai didi

c# - 带有参数的mysql odbc插入

转载 作者:行者123 更新时间:2023-11-29 07:09:13 26 4
gpt4 key购买 nike

谁能告诉我为什么我只将标志插入我的表而不是所有内容?

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 rejecting parameter

关于c# - 带有参数的mysql odbc插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5572492/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com