Database help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • javatech007
    New Member
    • Nov 2007
    • 51

    Database help

    Hi,
    I have an access database of bank customers which include a unique pin number for each customer.
    I have an atm part to my program and want the pin enrty form to read the unique pins from the database to allow access or not. What i have so far below only reads the first pin from my database! Any ideas?

    [CODE=vbNET]

    Private Sub btnEnter_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnEnter.Click

    Dim balance As New frmBalance

    If txtDisplay.Text = CStr(objDS.Tabl es(0).Rows(rowI ndex)("PIN")) Then
    Me.Hide()
    balance.Show()
    End If

    End Sub

    [/CODE]
    Last edited by debasisdas; Mar 14 '08, 07:03 AM. Reason: added code=vbnet tags
  • nateraaaa
    Recognized Expert Contributor
    • May 2007
    • 664

    #2
    What is the value of rowIndex? If you want to search the entire table you will need to use a loop.
    [CODE=vbnet] for(int i = 0; i < objDS.Tables.Ro ws.Count; i++)
    {
    If txtDisplay.Text = CStr(objDS.Tabl es(0).Rows(i)(" PIN")) Then
    Me.Hide()
    balance.Show()
    End If
    }
    [/CODE]

    Nathan
    Last edited by debasisdas; Mar 14 '08, 07:02 AM. Reason: added code=vbnet tags

    Comment

    • kunal pawar
      Contributor
      • Oct 2007
      • 297

      #3
      U can used rowfilter property of defaultview class of dataset.table() . this will help to filter record in ur datatable

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        How you will find the unique PIN ?

        Are you passing anything to the database like the user name or Account number or anything else ?

        Comment

        • javatech007
          New Member
          • Nov 2007
          • 51

          #5
          Originally posted by nateraaaa
          What is the value of rowIndex? If you want to search the entire table you will need to use a loop.
          [CODE=vbnet] for(int i = 0; i < objDS.Tables.Ro ws.Count; i++)
          {
          If txtDisplay.Text = CStr(objDS.Tabl es(0).Rows(i)(" PIN")) Then
          Me.Hide()
          balance.Show()
          End If
          }
          [/CODE]

          Nathan
          i did that and it shows up errors when 'int=0' is declared, for the '{' , and for (i) after rows!!

          Comment

          • javatech007
            New Member
            • Nov 2007
            • 51

            #6
            Originally posted by debasisdas
            How you will find the unique PIN ?

            Are you passing anything to the database like the user name or Account number or anything else ?
            each customer is given a unique pin that no one else can get so if they enter that number they can withdraw money. so no just the pin.

            Comment

            • javatech007
              New Member
              • Nov 2007
              • 51

              #7
              Originally posted by kunal pawar
              U can used rowfilter property of defaultview class of dataset.table() . this will help to filter record in ur datatable
              thank you.how would i use this?

              Comment

              • nateraaaa
                Recognized Expert Contributor
                • May 2007
                • 664

                #8
                Originally posted by javatech007
                i did that and it shows up errors when 'int=0' is declared, for the '{' , and for (i) after rows!!
                Sorry. That was the way that a for loop is written in C#. Here is how it should look in vb.net
                [CODE=vbnet]

                Dim balance As New frmBalance()

                For i As Integer = 0 To objDS.Tables(0) .Rows.Count - 1

                If txtDisplay.Text = DirectCast(objD S.Tables(0).Row s(i)("PIN"), String) Then

                Me.Hide()

                balance.Show()

                End If

                Next

                [/CODE]

                Nathan

                Comment

                • javatech007
                  New Member
                  • Nov 2007
                  • 51

                  #9
                  Originally posted by nateraaaa
                  Sorry. That was the way that a for loop is written in C#. Here is how it should look in vb.net
                  [CODE=vbnet]

                  Dim balance As New frmBalance()

                  For i As Integer = 0 To objDS.Tables(0) .Rows.Count - 1

                  If txtDisplay.Text = DirectCast(objD S.Tables(0).Row s(i)("PIN"), String) Then

                  Me.Hide()

                  balance.Show()

                  End If

                  Next

                  [/CODE]

                  Nathan
                  thanks you've been a great help so far but its throwing up an error for line 5 saying:
                  Unable to cast object of type 'System.Int32' to type 'System.String' .

                  Comment

                  • nateraaaa
                    Recognized Expert Contributor
                    • May 2007
                    • 664

                    #10
                    Replace the , String with , System.Int32 and that should fix your problem. Basically it is saying PIN is an integer type and the code on line 5 is trying to retrieve a string.

                    Nathan

                    Comment

                    • javatech007
                      New Member
                      • Nov 2007
                      • 51

                      #11
                      Originally posted by nateraaaa
                      Replace the , String with , System.Int32 and that should fix your problem. Basically it is saying PIN is an integer type and the code on line 5 is trying to retrieve a string.

                      Nathan
                      hi nathan,

                      it worked. thanks for everthing

                      Comment

                      • javatech007
                        New Member
                        • Nov 2007
                        • 51

                        #12
                        hi,

                        i've a new problem now. I trying to allow the user who entered their unique PIN to be able to view their bank balance. So Im trying to take their PIN and match it with their balance from my access database! I tried this but it doesnt work.

                        [CODE = .NET]

                        Private Sub frmBalance_Load (ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load

                        objDS.Clear()
                        objDA.FillSchem a(objDS, SchemaType.Sour ce, "CustomerAccoun ts")

                        objDA.Fill(objD S, "CustomerAccoun ts")

                        Dim objRow As DataRow
                        objRow = objDS.Tables("C ustomerAccounts ").Rows.Find(fr mATM.txtDisplay .Text.ToString)
                        txtBalance.Text = objRow.Item("Ba lance")

                        End Sub

                        [/CODE]

                        Comment

                        • nateraaaa
                          Recognized Expert Contributor
                          • May 2007
                          • 664

                          #13
                          When you say it doesn't work what does that mean? Are you not getting any data back for the balance? Is the code throwing an error? You may want to use a try catch block in your code to catch an exceptions being thrown.

                          Nathan

                          Comment

                          Working...