Results 1 to 7 of 7

Thread: Matching a textBox entry to a Primary Key in a DB table

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    4

    Matching a textBox entry to a Primary Key in a DB table

    Hi

    I hope someone can help me. I have an ATM machine connected to a server. A form takes a textBox entry as a PIN number and matches it to a card number in the same table which is the primary key. The card number is in a comboBox.Selected Item. I have used a dataset to fill the comboBox as the form loads. I have tried for days and got nowhere. Any advice would be appreciated. Thanks

  2. #2
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    Re: Matching a textBox entry to a Primary Key in a DB table

    What exactly are you trying to do?
    Thanks
    CoachBarker

    Code Bank Contribution
    Login/Manage Users/Navigate Records
    VB.Net | C#

    Helpful Links: VB.net Tutorial | C Sharp Tutorial | SQL Basics

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    4

    Re: Matching a textBox entry to a Primary Key in a DB table

    Hi

    Sorry I know it sounds really cofusing.

    I have a database with 5 tables representing a banking system. I have a form which is supposed to represent the ATM machine. The form has a comboBox to display all the cards in the system which I have filled via a dataset. A textBox to enter a Pin number and a button to check the pin against the card number which is the primary key of the table they are both in.

    Here is my problem. I am to match the pin to the card number in the same table using queries and I have failed after countless tries.

    Thanks really despondent VB student.

    Cally

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Matching a textBox entry to a Primary Key in a DB table

    How did you fill the dataset that is in the combo? Are you using displaymember, valuemember?

    What is the SQL that you wrote?

    Can you post the code you are trying?
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    4

    Re: Matching a textBox entry to a Primary Key in a DB table

    In the tools menu of Visual Basic I dragged a SqlDataAdapter onto the form and the query is SELECLT cardNumber, AccountID, Confiscated, PIN FROM ATMCards. Then I generated a DataSet from the DataAdapter to hold the results.

    In the code I then wrote on Form_Load SqlDataAdapter.Fill(DataSetCards.ATMcards)
    M)

    Now I have to write a command.Text query and the code to obtain a match for the PIN number to the cardNumber in the same table. I have tried quite a few queries and someone suggested an AddWithValue.

    The SqlCommandText query is SELECT PIN FROM ATMCards WHERE cardNumber = @cardNumber. Now when I enter a pin number in the text box and select a card number from the comboBox I get an error message - Error: No mapping exists from object type system.Data.Row.View to a known managed native provider. I have used an SqlDataAdapter.DataReader to try and match the fields and this is the message I get.

    Any advice would be welcome.

  6. #6
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Matching a textBox entry to a Primary Key in a DB table

    MY advice (and I know other don't agree) is never use the generated datasets. I allways create my own objects.

    But to your point I think

    Dim strSQL As String = String.Empty
    strSQL &= "Select Pin From ATMCards Where cardNumber = @cardNumber"
    now create a connection object.
    Create a command Oblect
    create a parameter for the command object
    parm.AddWithValue(@cardNumber,textbox.text)
    execute scaler on the command object.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  7. #7

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    4

    Re: Matching a textBox entry to a Primary Key in a DB table

    Thank you for taking the time to reply, I will get cracking with the code.

    Cally

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width