从 Access 数据库更新到 C# 中的文本框时尝试仅获取数字

发布于 2025-01-12 10:10:39 字数 673 浏览 1 评论 0原文

我刚刚开始使用 C#,并且表单上有一个文本框。我只想显示 ACCESS 数据库中的数字,就像存储在数据库中的字符串是 12Kg 但当我更新时我应该只返回值 ie12,我已经搜索但没有得到任何想法,我希望你能帮助我...


查询:

"Update Para Set PartNumber = '"+ txtPartNoL.Text + "', MacID = '" + cmb.SelectedValue.ToString() + "'"+" Para1 = '" + txtPara1L.Text + "', PType1 = '" + lblLPara1.Text + "'," + " val(LabourPara.Para4) = '" + txtPara4L.Text + "', PType4 = '" + lblLPara4.Text + "'," + " Qty = '" + txtQtyL.Text + "', PF = '" + txtPFL.Text + "', SF = '" + txtSFL.Text + "'," + " Amount = '" + txtAmt.Text + "'" + " WHERE QoNumber = '" + txtNo.Text + "' AND PartNumber = '" + txtPartNo.Text + "'";

I just started using C# and I a have a textbox on a form. I want to display only numbers from ACCESS database, Like string stored in database is 12Kg but when I do update i should return only value i.e.12, I have searched but not getting any idea, I hope you can help me...


Query:

"Update Para Set PartNumber = '"+ txtPartNoL.Text + "', MacID = '" + cmb.SelectedValue.ToString() + "'"+" Para1 = '" + txtPara1L.Text + "', PType1 = '" + lblLPara1.Text + "'," + " val(LabourPara.Para4) = '" + txtPara4L.Text + "', PType4 = '" + lblLPara4.Text + "'," + " Qty = '" + txtQtyL.Text + "', PF = '" + txtPFL.Text + "', SF = '" + txtSFL.Text + "'," + " Amount = '" + txtAmt.Text + "'" + " WHERE QoNumber = '" + txtNo.Text + "' AND PartNumber = '" + txtPartNo.Text + "'";

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴情 2025-01-19 10:10:39

您正在将所有内容更新为文本,这至少对于数量和金额而言是不可能的,因此请尝试:

sql = "Update Para Set PartNumber = '"+ txtPartNoL.Text + "', MacID = '" + cmb.SelectedValue.ToString() + "' " + 
"Para1 = '" + txtPara1L.Text + "', PType1 = '" + lblLPara1.Text + "', " + 
"LabourPara.Para4 = " + Val(txtPara4L.Text) + ", PType4 = '" + lblLPara4.Text + "', " + 
"Qty = " + txtQtyL.Text + ", PF = '" + txtPFL.Text + "', SF = '" + txtSFL.Text + "', " + 
"Amount = " + txtAmt.Text + " " + 
"WHERE QoNumber = " + txtNo.Text + " AND PartNumber = '" + txtPartNo.Text + "'";

但是,请避免这种连接混乱,并且 - 尽快 - 去学习如何使用参数

You are updating everything as text, which can't be true for at least quantity and amount, so try:

sql = "Update Para Set PartNumber = '"+ txtPartNoL.Text + "', MacID = '" + cmb.SelectedValue.ToString() + "' " + 
"Para1 = '" + txtPara1L.Text + "', PType1 = '" + lblLPara1.Text + "', " + 
"LabourPara.Para4 = " + Val(txtPara4L.Text) + ", PType4 = '" + lblLPara4.Text + "', " + 
"Qty = " + txtQtyL.Text + ", PF = '" + txtPFL.Text + "', SF = '" + txtSFL.Text + "', " + 
"Amount = " + txtAmt.Text + " " + 
"WHERE QoNumber = " + txtNo.Text + " AND PartNumber = '" + txtPartNo.Text + "'";

However, avoid this concatenating mess and - asap - go and learn how to use parameters.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文