[英]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.