how to check if textbox value is a multiple of a field in a database

Posted on 2007-08-11
Last Modified: 2013-11-07
I am using VB.Net 2005 SP1 Compact Framework 2.0 with MS SQL Server 2005 Compact.

I have a textbox called txtD that only accepts integers. I need to know how to compare that value to a value in field t_adc in tblTally and determine if txtD is a multiple of t_adc.

for example if t_adc = 3 then txtD would have to be 3, 6, 9, 12, 15 ...etc to be valid.
another example if t_adc = 2 then txtD would have to be 2, 4, 5, 8, 10...etc to be valid

How would I do that? See my code below to help me finish it off. I left a message where I need help.



        Dim ssceconn As New SqlCeConnection("Data Source = \Program Files\data\products.sdf"
        Dim readerCT As SqlCeDataReader
        Dim cmdCT As New SqlCeCommand("SELECT t_adc FROM  tblTally WHERE t_albl = 'Spec'", ssceconn)
        Dim dc As Integer
        readerCT = cmdCT.ExecuteReader

        While readerCT.Read
            dc = CInt(readerCT.Item("t_adc").ToString)
        End While

        ' Close the connection
        readerCT = Nothing

        ssceconn = Nothing

        If txtD.Text  is multiple of dc Then ' THIS IS WHERE I NEED HELP
            MsgBox("Valid  Entry.")
        End If

Question by:PBLack
    LVL 25

    Accepted Solution


    if isnumeric(txtD.Text) and ((txtD.Text / dc) = (txtD.Text \ dc)) then 'valid entry
    LVL 6

    Expert Comment

    Hi PBLack,

    Try this:

            If Val(txtD.Text) Mod 2 = 0 Then ' THIS IS WHERE I NEED HELP
                MsgBox("Valid  Entry.")
                MsgBox("inValid  Entry.")
            End If
    LVL 48

    Expert Comment


    You can create a new ArrayList, then fill it in your loop (all the possible values for your combination) and then compare if it mach. Look this simple example:

    Dim myArray As New ArrayList

    ' You loop with all possible values for your combination
    While readerCT.Read
    End While

    ' Compare
    If myArray.Contains(txtD.Text) Then
    End If

    myArray = Nothing

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now