简体   繁体   English

试图在MS Access中编辑文本字段,但它说它需要更多参数

[英]Trying to edit a text field in MS Access, but it says it needs more parameters

I'm trying to edit a textfield in an MS Access database. 我正在尝试在MS Access数据库中编辑文本字段。 I'm able to successfully edit a number, but if I try to edit a textfield it asks me for more parameters. 我能够成功编辑数字,但是如果我尝试编辑文本字段,它将要求我提供更多参数。 My code looks like this: 我的代码如下所示:

try
{
    ad.UpdateCommand = new OleDbCommand("Update Tabel1 set Navn=" + txt_navn.Text.ToString() + " where ID=" + txt_userID.Text + "", conn);
    ad.UpdateCommand = new OleDbCommand("Update Tabel1 set Niveau=" + txt_niveau.Text.ToString() + " where ID=" + txt_userID.Text + "", conn);
    conn.Open();
    ad.UpdateCommand.ExecuteNonQuery();
    conn.Close();
}
catch(Exception ex)
{
    MessageBox.Show(ex.Message);
    conn.Close();
}

Basically, the Navn text field won't accept any changes and asks for more parameters if I disable the Niveau line. 基本上,如果我禁用Niveau行,则Navn文本字段将不接受任何更改,并要求提供更多参数。 I've also tried having both within the same ad.UpdateCommand line, but that gave me an error. 我也尝试过将它们都放在同一个ad.UpdateCommand行中,但这给了我一个错误。

As it is now it doesn't give any error, but it just doesn't change the 'Navn' field in the database, the 'Niveau' field changes just fine. 到目前为止,它没有给出任何错误,但是它只是没有更改数据库中的“ Navn”字段,“ Niveau”字段更改也很好。 Do you guys have any idea? 你们有什么主意吗?

Navn may be reserved, so try to frame it. Navn可能是保留的,因此请尝试对其进行构图。 Also, there should be no reason to cast the text content of a textbox to string. 另外,应该没有理由将文本框的文本内容转换为字符串。 And, as mentioned, one call will do it: 而且,如上所述,一个电话就能做到:

ad.UpdateCommand = new OleDbCommand("Update Tabel1 Set [Navn] = '" + txt_navn.Text + "', Niveau = " + txt_niveau.Text + " Where ID = " + txt_userID.Text + "", conn);

Hope this will do the trick 希望这能解决问题

ad.UpdateCommand = new OleDbCommand("Update Tabel1 set Navn='" + txt_navn.Text.ToString() + "' where ID=" + txt_userID.Text + ";", conn);
ad.UpdateCommand = new OleDbCommand("Update Tabel1 set Niveau='" + txt_niveau.Text.ToString() + "' where ID=" + txt_userID.Text + ";", conn);

I have updated Navn='" + txt_navn.Text.ToString() + "' instead of Navn=" + txt_navn.Text.ToString() + " 我已经更新了Navn='" + txt_navn.Text.ToString() + "'而不是Navn=" + txt_navn.Text.ToString() + "

And same goes to the next command 下一条命令也一样

But the thing is it would only update Niveau and not Navn since you have the last command store in the ad.UpdateCommand so you can improvise your code like this 但事情是它只会更新Niveau而不是Navn因为你必须在最后一个命令店ad.UpdateCommand这样你就可以凑合这样你的代码

ad.UpdateCommand = new OleDbCommand("Update Tabel1 set Navn='" + txt_navn.Text.ToString() + "', Niveau='" + txt_niveau.Text.ToString() + "' where ID=" + txt_userID.Text + ";", conn);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Dapper,MS Access,整数和“没有为一个或多个必需参数提供值” - Dapper, MS Access, Integers and “no value given for one or more required parameters” 在 MS Access 数据库的双字段中插入空值(不带参数) - Insert null into double field in MS Access Database(not with parameters) 我正在尝试使用组合框和日期时间选择器将输入保存到ms Access数据库中,并说:条件表达式中的数据类型不匹配 - I am trying to save inputs using combo boxes and a date time picker to a ms access database and it says : Data type mismatch in criteria Expression Access女士。 System.Data.OleDb.OleDbException:没有为一个或多个必需参数提供值 - Ms Access. System.Data.OleDb.OleDbException: No value given for one or more required parameters MS-Access,OleDbCommand,获取“没有为一个或多个必需参数提供值” - MS-Access, OleDbCommand, Getting a “No value given for one or more required parameters” 使用c#和ms访问进行编辑 - Edit using c# and ms access 访问和编辑私有字段值 - Access and edit private field value 错误提示“没有为一个或多个必需参数提供值” - Error says "No value given for one or more required parameters" 此代码返回一个错误,指出“没有为一个或多个必需参数提供值” - this code returns an error that says " No value given for one or more required parameters" "尝试从 Access 数据库中删除时出现 C# OleDb 异常“没有为一个或多个必需参数提供值”" - C# OleDb Exception "No value given for one or more required parameters" while trying to delete from Access database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM