gpt4 book ai didi

c# - 从c#插入数据库

转载 作者:太空宇宙 更新时间:2023-11-03 22:49:13 26 4
gpt4 key购买 nike

<分区>

我使用这段代码很长时间没有问题。但是,现在当我尝试插入数据库时​​,出现此错误

ERROR [07002] [MICROSOFT] ODBC MICROSOFT ACCESS DRIVER] TOO FEW PARAMETERS EXPECTED 2.

谁能告诉我我做错了什么?

if (txtFullName.Text == "" || txtPostcode.Text == "")
{
MessageBox.Show("Please enter appropriate details in order to proceed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (txtFullName.Text != "" && txtFullName.Text != "")
{
OdbcCommand cmd = new OdbcCommand("INSERT INTO [Entry] ([FullName], Postcode) Values(@A, @B)", ConnectDb);
cmd.Parameters.AddWithValue("@A", "HI");
cmd.Parameters.AddWithValue("@B", "BY");

ConnectDb.Open();

try
{
int res = cmd.ExecuteNonQuery();

if (res > 0)
{
DialogResult dialogResult = MessageBox.Show("New Allocator saved! would you like to exit? ", "Saved", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

if (dialogResult == DialogResult.Yes)
{
//BackToAdminMainMenu();
}

if (dialogResult == DialogResult.No)
{
//Clear();
}
}
}
catch (Exception err)
{
MessageBox.Show("A database error has occurred: " + Environment.NewLine + err.Message);
}
finally
{
ConnectDb.Close();
}
}

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