SQL数据库未通过vb.net命令更新 [英] SQL database not getting updated by vb.net command

查看:49
本文介绍了SQL数据库未通过vb.net命令更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在传递以下简单命令来更新数据库中的表。该命令运行没有错误,但数据库未更新。有人可以指出我正在犯的错误。



I am passing the following simple command to update a table in database. The command runs without error but the database is not updated. Can someone pls point out the mistake i am making.

Dim Update As New SqlCommand("Update COMP set COMPN = @COMPN WHERE COMPC = @COMPC", connection)

      Update.Parameters.Add(New SqlParameter("@COMPC", (ddlCompanyCode.SelectedText)))
      Update.Parameters.Add(New SqlParameter("@COMPN", (txtCompanyName.Text)))

           Update.ExecuteNonQuery()

推荐答案

可能是 WHERE 条件不满意d,但您没有注意到,因为您的代码忽略了 ExecuteNonQuery 返回值(即受命令影响的行)。
Probably the WHERE condition is not satisfied, but you didn't notice because your code ignores the ExecuteNonQuery return value (that is the rows affected by the command).


我猜测COMPC字段是数字字段,但您将参数作为文本插入。



尝试:



I'm guessing the COMPC field is a numeric one, but you are inserting the parameter as text.

Try:

Update.Parameters.Add(New SqlParameter("@COMPC", CType(ddlCompanyCode.SelectedText, Int)))


ITS DONE。

我必须将组合框属性从selectedtext更改为文本。



但为什么?



不是所选文本属性的组合框应该用作与所有文本相关的文本。



我非常感谢Ron特别为社区支持留下深刻印象:) thnks
ITS DONE.
I have to change the combo box property from selectedtext to text.

But why??

Isn't the selected text property of combobox which should be used as text relates to all the texts.

I am greatful and highly impressed by the community support specially by Ron :) thnks


这篇关于SQL数据库未通过vb.net命令更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆