blocking account
-
basically i need to check a checkbox on an access database to therefore block the user from using that account. my code is wrong(below) plus the catch exception is brining up this message "No value given for one or more required parametres" i think this line of code could be the problem because i keep on getting warningsm on it :- If dr.Read() Then 'if the entry is correct (readable) can anyone recterfy my code please? Imports System.Data.OleDb Public Class Block Public conn As OleDbConnection Public comm As OleDbCommand Public dr As OleDbDataReader Public da As OleDbDataAdapter Dim icount As Integer Private Sub Btnblock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBlock.Click 'when the logon button is pressed Dim ManagerLogin As String 'declares the variable Try conn = New OleDbConnection 'establishes that conn is a new connection conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\PCBank.mdb" 'the name of the connection (name of the database on the end) conn.Open() 'opens the connection comm = New OleDbCommand 'establishes that comm is a new command comm.Connection = conn 'the connection for the command is the connection specified comm.CommandType = CommandType.Text 'the commands are in text ManagerLogin = "SELECT DISTINCT Password FROM Accounts WHERE ManagerID='" & Me.tbID.Text & "' " 'the variables value is an SQL command, selects value that is equal to the id AND password. ''MessageBox.Show(ManagerLogin) 'shows the sql command (only needed for testing) comm.CommandText = ManagerLogin 'the variable is declared as a command dr = comm.ExecuteReader 'gives the variable a value conn = New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=PCBank.mdb") conn.Open() comm = New OleDbCommand("insert into Accounts(Blocked) values('" & (chBlock.CheckState) & "')", conn) icount = comm.ExecuteNonQuery() MsgBox("record inserted") chBlock.Checked = False Catch ex As Exception MsgBox(ex.Message) If dr.Read() Then 'if the entry is correct (readable) Me.Close() Form2.Show() 'show the index varibale (form) 'close the current form
-
basically i need to check a checkbox on an access database to therefore block the user from using that account. my code is wrong(below) plus the catch exception is brining up this message "No value given for one or more required parametres" i think this line of code could be the problem because i keep on getting warningsm on it :- If dr.Read() Then 'if the entry is correct (readable) can anyone recterfy my code please? Imports System.Data.OleDb Public Class Block Public conn As OleDbConnection Public comm As OleDbCommand Public dr As OleDbDataReader Public da As OleDbDataAdapter Dim icount As Integer Private Sub Btnblock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBlock.Click 'when the logon button is pressed Dim ManagerLogin As String 'declares the variable Try conn = New OleDbConnection 'establishes that conn is a new connection conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\PCBank.mdb" 'the name of the connection (name of the database on the end) conn.Open() 'opens the connection comm = New OleDbCommand 'establishes that comm is a new command comm.Connection = conn 'the connection for the command is the connection specified comm.CommandType = CommandType.Text 'the commands are in text ManagerLogin = "SELECT DISTINCT Password FROM Accounts WHERE ManagerID='" & Me.tbID.Text & "' " 'the variables value is an SQL command, selects value that is equal to the id AND password. ''MessageBox.Show(ManagerLogin) 'shows the sql command (only needed for testing) comm.CommandText = ManagerLogin 'the variable is declared as a command dr = comm.ExecuteReader 'gives the variable a value conn = New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=PCBank.mdb") conn.Open() comm = New OleDbCommand("insert into Accounts(Blocked) values('" & (chBlock.CheckState) & "')", conn) icount = comm.ExecuteNonQuery() MsgBox("record inserted") chBlock.Checked = False Catch ex As Exception MsgBox(ex.Message) If dr.Read() Then 'if the entry is correct (readable) Me.Close() Form2.Show() 'show the index varibale (form) 'close the current form
I'm not sure, but it looks like you're inserting a new record into a table called Accounts. Shouldn't this be an UPDATE statement that changes as field in the record in question?
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007