以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  关于update语句  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=58261)

--  作者:zeta_123
--  发布时间:2014/10/14 17:17:00
--  关于update语句

Dim t1 As String = e.Form.Controls("textbox1").Value  (t1的数据在打开窗口时已提过来了,没有问题

Dim t2 As String  = e.Form.Controls("textbox2").Value

Dim t3 As String = e.Form.Controls("textbox3").Value

Dim cmd As New SQLCommand

Dim dr As DataRow

cmd.ConnectionName = "system"

If t2=t3 Then

cmd.CommandText = "Update {用户表} Set [用户密码] = \'" & t2 & "\'  Where [用户姓名]= \'" & t1 & "\'"

 Messagebox.show("更改密码成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)

 e.Form.Close

 

Else

    Messagebox.show("更改密码失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)

End If


第一次运行时成功了,后台密码列也改了,但是之后只提示成功,后台数据没有改过来,刚接触foxtable,不知道是哪错了



--  作者:Bin
--  发布时间:2014/10/14 17:19:00
--  
cmd.CommandText = "Update {用户表} Set [用户密码] = \'" & t2 & "\'  Where [用户姓名]= \'" & t1.trim() & "\'"

这样试试看,可能用户名有空格,匹配不到对应的数据

也有可能T1的值根本不对. 你messagebox.show(t1)看看

--  作者:zeta_123
--  发布时间:2014/10/14 17:37:00
--  
试了试,还是不行,t1其实就是_username的值,这个每次执行命令后它就已经显示了,因为在afterload  里的语句。然后输入t2,t3的值,上面的是“确定”按钮的代码,是不是我用的update不对呢
--  作者:Bin
--  发布时间:2014/10/14 17:37:00
--  
你按照我2楼的做了没? 
--  作者:zeta_123
--  发布时间:2014/10/14 17:52:00
--  
试了,提的结果和t1显示的人名是一样的。
--  作者:zeta_123
--  发布时间:2014/10/14 17:55:00
--  
关键是一直都提示“密码更改成功”,就是后台密码列的密码值还是老的数据,就是不更新,保存关闭在打开也没有更新。
--  作者:Bin
--  发布时间:2014/10/14 17:56:00
--  
messagebox.show(cmd.CommandText)

看看语句是什么,把这语句放到 数据库SQL命令窗口执行,看看是否有效果

--  作者:有点甜
--  发布时间:2014/10/14 18:00:00
--  

 你根本就没执行

 

 

 

Dim t1 As String = e.Form.Controls("textbox1").Value  (t1的数据在打开窗口时已提过来了,没有问题)

Dim t2 As String  = e.Form.Controls("textbox2").Value

Dim t3 As String = e.Form.Controls("textbox3").Value

Dim cmd As New SQLCommand

Dim dr As DataRow


cmd.C

If t2=t3 Then
   
    cmd.CommandText = "Update {用户表} Set [用户密码] = \'" & t2 & "\'  Where [用户姓名]= \'" & t1 & "\'"
    If cmd.ExecuteNonQuery > 0 Then
        Messagebox.show("更改密码成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)

        e.Form.Close
    Else
        Messagebox.show("更改密码失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
       
    End If
    
      
Else
   
    Messagebox.show("更改密码失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
   
End If


--  作者:zeta_123
--  发布时间:2014/10/15 8:16:00
--  
按有点甜的代码试了,成功了,不过  “cmd.C"  这个代码不太明白而且提示有错误,所以把这句代码去了,有关系吗?去掉后,是成功的。


--  作者:Bin
--  发布时间:2014/10/15 8:25:00
--  
那个是指定数据源名称,内部数据源的话,不用指定