2016-04-14 99 views
0

每當我跑我的程序我得到這個錯誤:類型「System.Data.OleDb.OleDbException」未處理的異常出現在system.data.dll

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll

Additional information: No value given for one or more required parameters.

Sub admininfoo() 
    Dim q As String = "Select * from Table2 where AdminPassword=" & AdminLogin.TextBox1.Text 
    Dim cmd As New OleDb.OleDbCommand(q, connection) 
    Dim reader As OleDb.OleDbDataReader = cmd.ExecuteReader() 

    reader.Read() 

    AdminInterface.Label2.Text = reader("Name") 


    reader.Close() 
End Sub 

順便說一句,我使用Visual Basic 2013和Microsoft Access數據庫

+0

那你爲什麼把這個問題標記爲C#? – Jakotheshadows

+0

對不起我的壞... –

回答

0

您沒有清理您的輸入。如果你的密碼有'?'字符,OleDb提供者會將其解釋爲一個參數,您需要通過這個參數,您應該做的是防止任何注入。

使用OleDbCommand.Parameters.AddWithValue方法添加您的參數。

Dim q As String = "Select * from Table2 where AdminPassword=?" 
Dim cmd As New OleDb.OleDbCommand(q, connection) 
cmd.Parameters.AddWithValue("AdminPassword", AdminLogin.TextBox1.Text) 
Dim reader As OleDb.OleDbDataReader = cmd.ExecuteReader() 
相關問題