在vb.net中更新数据的问题 [英] problem to update a data in vb.net

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

问题描述

我在后端数据库中只有一个列. ..
现在我要更新特定数据..
我该怎么办
我的代码是---

i have only one colum in back end database that is roll. ..
Now i want to update a particular data ..
how can i do this
My code is---

dim s1 as integer=TextBox1.Text
  str = "UPDATE  Table1 SET roll=" & TextBox1.Text & "  WHERE roll= " & s1 & " "
        cmd = New SqlCommand(str, cn)
        cmd.ExecuteNonQuery()

推荐答案

如果roll是字符串类型,除非您将单引号引起来,否则我认为您的查询不会起作用价值.另外,一种改进代码的方法是使用参数.请参见下面的示例.
If roll is a string type, I don''t think your query will work, unless you place single quotes around the values. In addition, one way to improve your code is to use parameters. See below for example.
str = "UPDATE Table1 SET roll=@rollVal1 WHERE roll=@rollVal2"
cmd = New Sqlommand(str, cn)
cmd.Parameters.AddWithValue("@rollVal1", TextBox1.Text)
cmd.Parameters.AddWithValue("@rollVal2", sl)
cmd.ExecuteNonQuery()




请参见此处 [




See here[^] for reference.


尝试使用这些代码,即可正常使用.

将s1变暗为integer = TextBox1.Text
str ="UPDATE Table1 SET roll ="& TextBox1.Text& "
cmd =新的SqlCommand(str,cn)
cmd.ExecuteNonQuery()
Try These code, it is working.

dim s1 as integer=TextBox1.Text
str = "UPDATE Table1 SET roll=" & TextBox1.Text & ""
cmd = New SqlCommand(str, cn)
cmd.ExecuteNonQuery()


这篇关于在vb.net中更新数据的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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