+ -
当前位置:首页 → 问答吧 → 求助。vb.net如何更新MYSQL数据库里某个表的值?

求助。vb.net如何更新MYSQL数据库里某个表的值?

时间:2011-12-09

来源:互联网

我已经学会查询并显示MYSQL数据库里的信息了。可是我研究了好久。都没学会如何更新数据库表的值。我的查询是这样的。
 connStr = String.Format("Server=" & Server & ";Port=" & Port & ";Database=" & db & ";Uid=" & User & ";Pwd=" & Pass & "; pooling=false;")
  Dim sql As String = "select password,salt,uid,username from pre_ucenter_members where username='" & username & "'"
  Dim ds As New System.Data.DataTable
  Dim cmd As New MySqlDataAdapter(sql, connStr)
  cmd.Fill(ds)
  If ds.Rows.Count > 0 Then
  .............  
   
  MsgBox("用户登陆成功!", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "用户登陆成功!")

   
  Else
  MsgBox("用户密码错误!", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "用户密码错误!")
  password1.Focus()
  ds.Dispose()
  End If
  ...............  

 End If


我的更新语句是这样的。

 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  Dim connStr As String
  connStr = String.Format("Server=" & Server & ";Port=" & Port & ";Database=" & db & ";Uid=" & User & ";Pwd=" & Pass & "; pooling=false;")
  Try
  Dim sqlstr As String
  '定义一个修改语句
  sqlstr = "update count set ext6='" & 101 & "' where uid=1"
  '设置Command对象
  Dim Comm As New MySqlCommand(sqlstr)
  Comm.ExecuteNonQuery()
  '关闭数据库连接
  Comm.Connection.Close()
  MsgBox("用户修改成功。", MsgBoxStyle.OkOnly + _
  MsgBoxStyle.Exclamation, "用户修改成功")
  Catch ex As Exception
  MsgBox("添加失败。", MsgBoxStyle.OkOnly + MsgBoxStyle.Exclamation, "添加失败")
  End Try
  End Sub

提示修改用户失败。。。。不知道怎么写才是正确的更新语句。。。。。
提示修改用户失败。。。。不知道怎么写才是正确的更新语句。。。。。
提示修改用户失败。。。。不知道怎么写才是正确的更新语句。。。。。
提示修改用户失败。。。。不知道怎么写才是正确的更新语句。。。。。

作者: hsx49949046   发布时间: 2011-12-09

sqlstr = "update count set ext6='" & 101 & "' where uid=1"

101是啥?变量吗?

sqlstr = "update count set ext6='101' where uid=1"

作者: eaqpi   发布时间: 2011-12-09

dim ext6 as string ="101"

sqlstr = "update count set ext6='" & ext6 & "' where uid=1"

 
------------------

dim ext6 as integer =101
sqlstr = "update count set ext6=" & ext6 & " where uid=1"

作者: eaqpi   发布时间: 2011-12-09

相关阅读 更多