具有MS访问权限的vb.net中的update语句中的语法错误 [英] Syntax error in update statement in vb.net with MS access

查看:105
本文介绍了具有MS访问权限的vb.net中的update语句中的语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个更改密码形式,我需要通过验证UID和指定或类型更新密码,但我收到错误更新语句中的语法错误,下面我scode快照:



 尝试 

adp = OleDbDataAdapter( select * from Login,con)
dt.Clear()
adp.Fill(dt, 登录
str = 更新登录设置密码=' + txtNpassword.Text + 'where Type =' + cbDesignation.Text + < span class =code-string>'和UserId =' + txtuname.Text + '
cmd = OleDbCommand(str,con)
Dim i As 整数
对于 i = 0 dt.Tables( 0 )。Rows.Count - 1
如果(cbDesignation.Text = dt.Tables( 0 ).Rows(i).Item( 1 txtuname.Text = dt.Tables( 0 )。行(i).Item( 2 ))然后
UID = True
退出 For

End If
下一步
如果 UID = True 然后
con.Open()
cmd.ExecuteNonQuery()
MsgBox( 密码已成功更改,MsgBoxStyle.Information)
其他
MsgBox( 密码未更改,MsgBoxStyle.Information)

结束 如果


Catch ex As 异常
MessageBox.Show(ex.Message)

< span class =code-keyword>最后

如果(con.State = ConnectionState.Open)然后
con.Close()

结束 如果
UID = 错误

结束 尝试

解决方案

这里出现两个主要的no-nos:

1)不要连接字符串来构建SQL命令。它让您对意外或故意的SQL注入攻击持开放态度,这可能会破坏您的整个数据库。请改用参数化查询。

2)绝不以明文形式存储密码 - 这是一个主要的安全风险。有关如何在此处执行此操作的信息:密码存储:如何做到这一点。 [ ^ ]



如果你修复了这两个,你的语法错误很有可能会同时消失。

http:// social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/efee431e-1381-4cde-b488-7d75df01e571 [ ^ ]





http:// go4answers。 webhost4life.com/Example/syntax-error-update-statement-147482.aspx [ ^ ]


I am a having a change passwrod form where I need to update password with verifying UID and Designation or type, But I am getting error "Syntax error in update statement", below i scode snapshot:

Try

    adp = New OleDbDataAdapter("select * from Login", con)
    dt.Clear()
    adp.Fill(dt, "Login")
    str = "Update Login set Password='" + txtNpassword.Text + "' where Type='" + cbDesignation.Text + "' and UserId='" + txtuname.Text + "'"
    cmd = New OleDbCommand(str, con)
    Dim i As Integer
    For i = 0 To dt.Tables(0).Rows.Count - 1
        If (cbDesignation.Text = dt.Tables(0).Rows(i).Item(1) And txtuname.Text = dt.Tables(0).Rows(i).Item(2)) Then
            UID = True
            Exit For
            
        End If
    Next
    If UID = True Then
        con.Open()
        cmd.ExecuteNonQuery()
        MsgBox("Password Changed successfully", MsgBoxStyle.Information)
    Else
        MsgBox("Password Not changed", MsgBoxStyle.Information)

    End If


Catch ex As Exception
    MessageBox.Show(ex.Message)

Finally
    If (con.State = ConnectionState.Open) Then
        con.Close()

    End If
    UID = False

End Try

解决方案

Two major no-nos appear here:
1) Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
2) Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]

If you fix those two, there is a good chance that your syntax error will disappear at the same time.


http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/efee431e-1381-4cde-b488-7d75df01e571[^]


http://go4answers.webhost4life.com/Example/syntax-error-update-statement-147482.aspx[^]


这篇关于具有MS访问权限的vb.net中的update语句中的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆