2016-07-31 77 views
0

我有引发错误的代码 - 我需要你的帮助来解决它。解决更新查询中的错误

的错误是

语法错误在更新语句

我的代码:

Try 
    Dim conn As OleDbConnection = New OleDbConnection(My.Resources.ConnectionString) 
    Dim cmd As OleDbCommand 

    conn.Open() 

    Dim Sql As String = "select * from Administretor" 
    cmd = New OleDbCommand(Sql, conn) 

    Dim userE, userR As String 
    userE = txtOldPass.Text 

    Dim reder As OleDbDataReader = cmd.ExecuteReader() 

    While reder.Read() 
     userR = reder.Item(0) 
    End While 

    If userE = userR Then 
     If txtNewPass.Text = txtNewConfromPass.Text And txtNewConfromPass.Text <> "" And txtNewPass.Text <> "" Then 
      Sql = "UPDATE Administretor SET PASSWORD='" & txtNewPass.Text & " where LogIn_id=" & txtOldPass.Text & "" 

      Dim cmd0 As OleDbCommand = New OleDbCommand(Sql, conn) 
      cmd0.ExecuteNonQuery() 
     Else 
      MsgBox("Make sure that you have entered new password in both text Box and they both are same...!") 
     End If 
    Else 
     MsgBox("Enter the correct Username") 
    End If 

    MsgBox("Done 2") 
Catch ex As OleDbException 
    MsgBox(ex.Message) 
End Try 
+0

它仍然引发错误,它是相同的 –

+0

哪个RDBMS是这样的?请添加一个标签来指定您是使用'mysql','postgresql','sql-server','oracle'还是'db2' - 或者其他的东西。 –

回答

0

在这一部分中,
"UPDATE Administretor SET PASSWORD='" & txtNewPass.Text & " where ...

的密码会我在它之前有一个单一的报价,之后没有单一的报价。

将其更改为:
"UPDATE Administretor SET PASSWORD='" & txtNewPass.Text & "' where ...
注意这里额外的单引号---------------------------- ------------^

+0

你可以告诉我如何使用adepter –

+0

只需更改你的代码,在我给你展示的地方添加额外的单引号。 'adepter'是什么意思? –

+0

它仍然引发了一个错误,它是相同的 –

1

两个错误

"UPDATE Administretor SET PASSWORD='" & txtNewPass.Text & " where LogIn_id=" & txtOldPass.Text & "" 
                 ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
                  |     | 
           Missing single quote here---+     | 
                       | 
    LogIn_Id will never equal the old password--------------------------------+ 

但除了简单的语法错误,你从构建SQL出件,包括用户的输入有一个巨大的SQL注入漏洞。

0

添加这句法:

Sql = "UPDATE Administretor SET PASSWORD='" & txtNewPass.Text & " where LogIn_id=" & txtOldPass.Text & "" 

Clipboard.SetText(Sql) 

查询会在你的剪贴板。在SQL上运行它(无论您使用哪种方式),然后查看查询是否顺利运行?

请向我们展示查询生成功能以及从SQL直接运行时产生的错误。