以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]更新SQL数据问题  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=19117)

--  作者:jaegea
--  发布时间:2012/4/27 17:39:00
--  [求助]更新SQL数据问题

Dim TimingNumber As String = e.Form.Controls("TimingNumber").Value
Dim UserName As String = e.Form.Controls("UserName").Value
Dim UserGroup As String  = e.Form.Controls("UserGroup").Value
Dim PassWord As String = e.Form.Controls("PassWord").Value
Dim Post As String = e.Form.Controls("Post").Value
Dim Position As String = e.Form.Controls("Position").Value
Dim Authority As WinForm.CheckBox
Authority = e.Form.Controls("Authority")
Dim OldUserName As String
If e.Form.Controls("PassWord1").Value <> e.Form.Controls("PassWord").Value Then
 Messagebox.show("請輸入登錄工號!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If
Dim cmd As New SQLCommand
Dim Parts() As String = e.Form.Text.Split("-")
OldUserName =  Parts(Parts.Length -1)
cmd.C
If TimingNumber = "" Then
    Messagebox.show("請輸入登錄工號!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
End If
Dim F As Integer
If Authority.Checked = False Then
   F = 0
  Else
   F = 1
End If
cmd.CommandText = "Update {用戶表} Set [工號] =  \'" & TimingNumber & "\', [用戶名] = \'" & UserName & "\',[部門] = \'" & UserGroup  & "\', [職務] = \'" & Post & "\', [職位] = \'" & Position & "\', [特殊權限] = \'" & F & "\', [密碼] = \'" & Password & "\' Where [用戶名]= \'" & OldUserName & "\'"
If cmd.ExecuteNonQuery = 1 Then \'返回1表示更改成功
   Messagebox.show("更改用戶信息成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    If Forms("用戶管理").Opened Then
        With Forms("用戶管理").Controls("ListBox1")
            .Items(.SelectedIndex) = UserName
        End With
    End If
    e.Form.Close
  Else
    Messagebox.show("更改用戶失敗!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If

 

 

总是更改用户失败,不知道哪里出问题,请高手帮忙看看


--  作者:mr725
--  发布时间:2012/4/27 18:45:00
--  

If e.Form.Controls("PassWord1").Value <> e.Form.Controls("PassWord").Value Then
 Messagebox.show("請輸入登錄工號!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If   【这里只是提示,没有中止后面代码执行】

 

Dim Parts() As String = e.Form.【这里缺少点什么】Text.Split("-")
OldUserName =  Parts(Parts.Length -1)

 

······


--  作者:jaegea
--  发布时间:2012/4/28 8:05:00
--  

加上Return了,還是一樣

第二個地方是設置窗口標題的,不影响SQL,現在是SQL更新失敗

[此贴子已经被作者于2012-4-28 8:05:59编辑过]

--  作者:狐狸爸爸
--  发布时间:2012/4/28 10:08:00
--  

如果总是提示更改用户失败,最优可能是你合成的update语句的条件有问题,以至于没有

 

cmd.CommandText = "Update {用戶表} Set [工號] = \'" & TimingNumber & "\', [用戶名] = \'" & UserName & "\',[部門] = \'" & UserGroup & "\', [職務] = \'" & Post & "\', [職位] = \'" & Position & "\', [特殊權限] = \'" & F & "\', [密碼] = \'" & Password & "\' Where [用戶名]= \'" & OldUserName & "\'"
MessageBox.show(cmd.CommandText)

 

 


--  作者:jaegea
--  发布时间:2012/4/28 11:48:00
--  

除子[特殊權限]列是邏輯列之外,其它所有列都是字符列,sql的邏輯列updata是整數0或1這裡也沒錯呀,但還是出問題,望指點,謝謝


图片点击可在新窗口打开查看此主题相关图片如下:001.jpg
图片点击可在新窗口打开查看

[此贴子已经被作者于2012-4-28 11:49:48编辑过]

--  作者:狐狸爸爸
--  发布时间:2012/4/28 11:51:00
--  
逻辑列用0,不是\'0\', 不要单引号。
--  作者:jaegea
--  发布时间:2012/4/28 11:58:00
--  

還是一樣

 


图片点击可在新窗口打开查看此主题相关图片如下:002.jpg
图片点击可在新窗口打开查看

--  作者:jaegea
--  发布时间:2012/4/28 11:59:00
--  
舊用戶名錯了,我再試試
--  作者:jaegea
--  发布时间:2012/4/28 12:02:00
--  
是Where [用戶名]= \'" & OldUserName & "\'"這裡出了問題,以工號登錄的這裡弄錯了,弄成了用戶名