SQL UPDATE语句-使用WHERE的无效列名

时间:2019-07-17 06:18:00

标签: vb.net

我正在尝试对密码字段进行简单的更新,但始终收到与WHERE语句有关的错误,并且guidPasscode为“无效的列名'guidPasscode'。

我知道这可能很简单,但是两天后我陷入了困境,只是看不到问题。
尽管我已从此代码中删除了调试信息,但所有数据内容都是正确的。

在表中:
UID是唯一标识符
DeviceType是varchar
uPassword是一个varchar

UIDPasscode是随该应用程序传递的GUID。

谢谢

n+1

更新:

我刚刚尝试了以下操作,但是现在出现错误;
无效的列:newPassword

 Public Function updatePasscode(ByVal UIDpasscode As String, AppMode As String, Optional ByVal exTmplList As List(Of String) = Nothing) As Boolean

        Dim connection As SqlConnection = New SqlConnection(mConnectionString)
        connection.Open()
        Dim DeviceTypes As String = "P1"     

        Try

            Dim i As Integer
            Dim guidPasscode As New Guid(UIDpasscode)

            For i = 0 To 0

                Dim scanCommand As SqlCommand = New SqlCommand()
                scanCommand.Connection = connection
                scanCommand.CommandType = 1 ' CommandType.Text

                Dim newPassword As String = exTmplList(i)

                Dim updateSql As String = "UPDATE tblUserScans SET DeviceType = DeviceTypes, uPassword = newPassword WHERE UID = guidPasscode"

                scanCommand.CommandText = updateSql

                scanCommand.ExecuteNonQuery()

                scanCommand.Dispose()
                scanCommand = Nothing
            Next

更新:

根据@muffi的建议,我更改了;

               For i = 0 To 0

                Dim scanCommand As SqlCommand = New SqlCommand()
                scanCommand.Connection = connection
                scanCommand.CommandType = 1 ' CommandType.Text

                Dim newPassword As String = exTmplList(i)

                updateSql = "Update tblUserScans SET DeviceType = 'P1', uPassword = newPassword  Where ( UID = '" & UIDpasscode & "')"

                scanCommand.Connection = mSqlconnection
                scanCommand.CommandType = CommandType.Text

                scanCommand.Parameters.Add("@uPassword", SqlDbType.VarChar)
                scanCommand.Parameters("@uPassword").Value = newPassword

                scanCommand.CommandText = updateSql

                scanReturn = scanCommand.ExecuteNonQuery()

updateSql = "Update tblUserScans SET DeviceType = 'P1', uPassword = newPassword  Where ( UID = '" & UIDpasscode & "')"

工作得很好。

1 个答案:

答案 0 :(得分:-1)

尝试:

Dim updateSql As String = "UPDATE tblUserScans SET DeviceType = DeviceTypes, uPassword = newPassword WHERE UID = '" & guidPasscode.ToString() & "';"