none
Data provided in ATM simulated in visual basic are not being validated in SQL RRS feed

  • Question


  • Good afternoon,

    I am facing a problem with Visual Basic when validating data in SQL. I am simulating an ATM, in which I enter a Card ID and PIN, each of that data is stored on the SQL server. I connect to the database without inconvenience. I use a stored procedure in vb.net and SQL with an authentication class, but I enter any data and it is as if it does not validate anything. Moving from one form to another regardless of the data you enter. I need help with this please. Thanks in advance.



    • Edited by Jedaovva Friday, November 29, 2019 1:55 AM
    Thursday, November 28, 2019 9:50 PM

All replies

  • Jedaovva,

    You don't provide data to visual basic. You can provide data to your program made with the tool Visual Basic.  

    However, it seems you did something wrong. What it is, we cannot see, but surely something you did.

    Your question sounds like somebody who tells: "my hammer hits me on the thumb, my hammer is wrong".  


    Success
    Cor

    Thursday, November 28, 2019 10:54 PM
  • It's a complete guessing game with just a narrative, best to show relevant code.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Thursday, November 28, 2019 11:21 PM
    Moderator
  • Hi Cor,

    Thanks for the correction. I have several classes in use. I can show you the code of each one to see you could determine the problem. In addition to this when I execute a debug I see no error.
    • Edited by Jedaovva Friday, November 29, 2019 1:53 AM
    Friday, November 29, 2019 12:33 AM
  • DB Connection Class:

    Imports System
    Imports System.Data
    Imports System.Data.SqlClient


    Public Class clsDBConnection

        Private _strUserDB As String
        Private _strPassDB As String
        Private _strNameDB As String
        Private _strSRVName As String
        Private _strConnection As String

        Private adAdaptator As SqlDataAdapter
        Private tbTable As DataTable
        Private drRegister As SqlDataReader

        Public strCommand As String

        Public _Error As Boolean
        Public _Message As String


        Public Sub New()

            With ATMApp3.My.Settings
                _strSRVName = .strNameSRV.ToString
                _strNameDB = .strNameDB.ToString
                _strUserDB = .strUserDB
                _strPassDB = .strUserPassDB
            End With

            _strConnection = "Data Source=JOVALLES-PC\SQLSERVEREX;Initial Catalog=" & _strNameDB & ";User ID=" & _strUserDB & ";Password=" & _strPassDB

            Try
                Dim DBConnection As New System.Data.SqlClient.SqlConnection(_strConnection)
                 DBConnection.Open()
                MsgBox("CONNECTED")
            Catch ex As Exception
                MsgBox("Error to connect due to: " + ex.ToString)
            End Try

        End Sub

        Public Function Authentication(ByVal SPName_p As String, ByVal Card_p As String, ByVal Pin_p As String) As SqlDataReader


            Dim DBConnection As New System.Data.SqlClient.SqlConnection(_strConnection)
            Dim cmd As New SqlClient.SqlCommand(pNombreSP, dbConexion)
            cmd.CommandType = CommandType.StoredProcedure


            Dim Card_par As New SqlClient.SqlParameter("@CARD_NUM", SqlDbType.VarChar)
            Card_par.Direction = ParameterDirection.Input
             Card_par.Value = Card_p

            Dim Pin_par As New SqlClient.SqlParameter("@PIN", SqlDbType.VarChar)
             Pin_par.Direction = ParameterDirection.Input
             Pin_par.Value = Pin_p


            With cmd.Parameters
                .Add(Card_par)
                .Add(Pin_par)
            End With


            Try
                If DBConnection.State = ConnectionState.Closed Then
                     DBConnection.Open()
                End If


                drRegister = cmd.ExecuteReader

                If drRegister.HasRows Then
                    Return drRegister
                Else
                    _Error = True
                    _Message = "There is not data registered in the database"
                     DBConnection.Close()
                    Return Nothing
                End If

            Catch ex As Exception
                 DBConnection.Close()
                _Error = True
                _Message = ex.Message.ToString
                Return Nothing
            End Try

        End Function


    End Class

    #############################################################

    Authentication class:

        Imports System
        Imports System.Data
        Imports System.Data.SqlClient


        Public Class clsAuthentication

        Public _CardNum As String
        Public _Pin As String

        Public Function Authentication() As Boolean

            Dim oSecurity As New clsSecurity
            Dim strHash As String = oSecurity.EncryptMD5(_Pin)

            Dim oConnection As New clsDBConnection

            With oConnection
                  
                Dim drRegister As SqlDataReader

                ._Error = False
                ._Message = ""
                drRegister = .Authentication("up_authentication", _CardNum, strHash)

                If ._Error = False Then
                    If drRegister.HasRows Then
                        Return True
                    End If

                End If

            End With

            Return False


        End Function


    End Class


    ###############################################################

    Security class for password encryption:

    Imports System.Text
    Imports System.Security.Cryptography

    Public Class clsSecurity

        Public Function EncryptMD5(ByVal cleanString As String) As String
            Dim clearBytes As [Byte]()
            clearBytes = New UnicodeEncoding().GetBytes(cleanString)
            Dim hashedBytes As [Byte]() = CType(CryptoConfig.CreateFromName("MD5"), HashAlgorithm).ComputeHash(clearBytes)
            Dim hashedText As String = BitConverter.ToString(hashedBytes)
            Return hashedText
        End Function


    End Class

    ###############################################################

    Card ID insert Form:

    Public Class FRM_InsertCardID

        Private Sub BTN_Ok_Click(sender As Object, e As EventArgs) Handles BTN_Ok.Click

            Dim oAuthentication As New clsAuthentication
            Dim bExist As Boolean = True

            With oAuthentication
                ._CardNum = TXB_CardID.Text
                ._Pin = FRM_PIN.TXB_PIN.Text
                bExist = .Authentication()
            End With

            If Not bExist Then
                MsgBox("There is not data")
            Else
                FRM_PIN.Show()
                TXB_CardID.Text = ""
                Me.Hide()

            End If

        End Sub

    End Class


    ################################################################

    PIN Insert Form:

    Public Class FRM_PIN

        Private Sub BTN_Ok_Click(sender As Object, e As EventArgs) Handles BTN_Ok.Click


            Dim oAuthentication As New clsAuthentication
            Dim bExist As Boolean = True

            With oAuthentication
                ._CardNum = FRM_InsertCardID.TXB_CardID.Text
                ._Pin = TXB_PIN.Text
                bExist = .Authentication()
            End With

            If Not bExist Then
                MsgBox("There is not data")
            Else
                FRM_Transaction.Show()
                TXB_PIN.Text = ""
                Me.Hide()

            End If


        End Sub

    End Class



    • Edited by Jedaovva Friday, November 29, 2019 1:10 AM
    Friday, November 29, 2019 12:49 AM
  • How about the definition for the Stored Procedure ?

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Friday, November 29, 2019 12:53 AM
    Moderator
  • This is in SQL:

    USE [SigmasBank]
    GO
    /****** Object:  StoredProcedure [dbo].[up_authentication]    Script Date: 11/28/2019 9:29:26 PM ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[up_authentication] 
     @CARD_NUM VARCHAR(19),
     @PIN VARCHAR(50)
     AS 
     SELECT COUNT(*) AS TOTAL 
     FROM AUTHENTICATION A
     WHERE 
         A.CARD_NUM = @CARD_NUM AND
    A.PIN_NUM = @PIN

    Friday, November 29, 2019 1:32 AM
  • The stored procedure is working properly in SQL.


    • Edited by Jedaovva Friday, November 29, 2019 3:21 PM
    Friday, November 29, 2019 1:59 AM
  • Hi,

    Could you share us a screen shot about your current result and your SQL table structure? I don't quite understand it now.

    Please pay attention to privacy protection when you provide.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, December 3, 2019 7:54 AM
    Moderator
  • Maybe replace

       Dim cmd As New SqlClient.SqlCommand(pNombreSP, dbConexion)

    with

       Dim cmd As New SqlClient.SqlCommand(pNombreSP, DBConnection)

    because it is unclear what dbConexion is.

    Tuesday, December 3, 2019 11:28 AM