Hi pliz assist me, I need a code that can allow the login form to search for pin number stored in another form example when a customer enters the pin number and clicks ok button the login form searches if the pin number exists in the bank details form ..thanx in advance

Dani AI

Generated

Good summary and a practical pattern to apply here — clarified the PIN is in a database table and already showed a direct query approach. The key improvements are: validate input, use parameterized queries to avoid SQL injection, dispose connections with Using, and return a simple Boolean for the login flow. Replace table/column names and the connection string setting with your own values.

Public Function PinExists(pin As String) As Boolean
    If String.IsNullOrWhiteSpace(pin) Then Return False

    Dim sql As String = "SELECT COUNT(1) FROM BankAccounts WHERE Pin = @pin"
    Dim connStr As String = My.Settings.BankConnectionString ' replace with your setting

    Try
        Using cn As New System.Data.SqlClient.SqlConnection(connStr)
            Using cmd As New System.Data.SqlClient.SqlCommand(sql, cn)
                cmd.Parameters.Add("@pin", System.Data.SqlDbType.VarChar, 20).Value = pin.Trim()
                cn.Open()
                Return Convert.ToInt32(cmd.ExecuteScalar()) > 0
            End Using
        End Using
    Catch ex As Exception
        ' Log securely; return False to avoid exposing details
        Return False
    End Try
End Function

Security notes: never concatenate user input into SQL (risk shown in earlier posts). If your PINs are stored in plain text, move to a salted, slow hash (PBKDF2/Rfc2898DeriveBytes or an external library) and compare hashes instead. Enforce rate limits / lockouts on failed attempts and always send forms over TLS.

Troubleshooting: if you use Access/OleDb, switch to OleDbConnection and use positional parameters (?), and add parameters in order. If the column is numeric, use the appropriate SqlDbType (Integer) and convert the input safely. If the function always returns False, check the connection string, table/column names, DB permissions, and test the query directly in the database tool. This builds on ’s example and the MSDN pointer mentioned but uses safer patterns suitable for production.

Recommended Answers

All 7 Replies

Hi pliz assist me, I need a code that can allow the login form to search for pin number stored in another form example when a customer enters the pin number and clicks ok button the login form searches if the pin number exists in the bank details form ..thanx in advance

post code

Sorry I made an error the form should check if the pin number exist in the bank table in the database ..thanks

Hi,

The first thing you will need to do is create a connection string to your database. I will assume that you have already done this. We performed a similar function in a project I was working on and we created a function that would return whether or not the person logging in was a Manager. You should be able to tweak this code to make it work. NOTE: not being on the table threw an exception which was caught in the
catch exception portion of this code. Also, "gstrConn" was a global variable that holds the connection string (set in the form load event - gstrConn = My.Settings.SouthRefundsConn.ToString). You can use this technique or you can simply type out the entire connection string inside the parenthesis (like this "( Dim conn As New OleDbConnection(My.Settings.SouthRefundsConn.ToString)).
[Public Function MANAGERID()

'THIS FUNCTION READS THE tblMANAGEMENT TABLE IN THE REFUNDS DATABASE TO DETERMINE IF THE
'USER LOGGED INTO THE APPLICATION IS A MANAGER.
'IF THE USER IS ON tblMANAGEMENT, THE MANAGERID VALUE WILL BE THE EMPLOYEE'S ID.
'IF THE USER IS NOT ON tblMANAGEMENT, THE MANAGERID VALUE WILL BE SET TO ""
Dim conn As New OleDbConnection(gstrConn)
Dim strInsert As String
Dim returnValue As Object

Try
strInsert = "SELECT [EMPLOYEE_ID] FROM [tblMANAGEMENT] " & _
" WHERE [EMPLOYEE_ID] = '" & Mid(strRACF, 3, 4) & "'"

Dim cmd As New OleDbCommand

cmd.CommandText = strInsert
cmd.CommandType = CommandType.Text
cmd.Connection = conn
conn.Open()

returnValue = cmd.ExecuteScalar

Return returnValue

Catch ex As Exception
Return ""
Finally
conn.Close()
End Try

End Function]

commented: use code tags next time -1

Hi were u using vb2008 to solve the problem??

No, we were using Visual Studio 2005.

No, we were using Visual Studio 2005.

Visual Studio is an IDE, VB2008 is part of Visual Studio

check here

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.