進口System.Data.OleDb.executenonquery()錯誤沒有用於一個或多個必需參數給出
公共類LoginForm的 昏暗CONNSTRING作爲字符串=「提供者= Microsoft.ACE.OLEDB.12.0值;數據源= C:\ Users \ User \ Desktop \ thesis \ YBIM.accdb「 Dim conn As New OleDbConnection 'TODO:插入代碼以使用提供的用戶名和密碼 '(請參閱http://go.microsoft.com/fwlink/?LinkId=35339)執行自定義驗證。
'然後可以將自定義主體附加到當前線程的主體,如下所示: 'My.User.CurrentPrincipal = CustomPrincipal '其中CustomPrincipal是用於執行身份驗證的IPrincipal實現。 「隨後,My.User將返回封裝在CustomPrincipal對象標識信息 」比如用戶名,顯示名稱等
Private Sub LoginForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
conn.ConnectionString = connstring
If conn.State = ConnectionState.Closed Then
conn.Open()
MsgBox("welcome")
Else
MsgBox("Cannot connect to database")
End If
End Sub
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim SqlQuery As String = ("SELECT * FROM tablelogin WHERE Username= @field1 AND [email protected]")
Dim SqlCommand As New OleDbCommand
Dim Sqlrdr As OleDbDataReader
With SqlCommand
.CommandText = SqlQuery
.Connection = conn
.Parameters.AddWithValue("@field1", UsernameTextBox.Text)
.Parameters.AddWithValue("@field2", PasswordTextBox.Text)
.ExecuteNonQuery()
End With
Sqlrdr = SqlCommand.ExecuteReader()
If (Sqlrdr.Read() = True) Then
home.ShowDialog()
Me.Hide()
Else
MsgBox("wong input")
End If
End Sub
末級
爲什麼既'.ExecuteNonQuery'和'.ExecuteReader'? – Tobberoth
我該怎麼辦? – user2992360