Link to home
Start Free TrialLog in
Avatar of Todd MacPherson
Todd MacPhersonFlag for Canada

asked on

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

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.

Thanks

PBLack

        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
        ssceconn.Open()
        readerCT = cmdCT.ExecuteReader

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

        ' Close the connection
        readerCT.Close()
        readerCT.Dispose()
        readerCT = Nothing

        ssceconn.Close()
        ssceconn.Dispose()
        ssceconn = Nothing

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

ASKER CERTIFIED SOLUTION
Avatar of clockwatcher
clockwatcher

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hatem72
hatem72

Hi PBLack,


Try this:

        If Val(txtD.Text) Mod 2 = 0 Then ' THIS IS WHERE I NEED HELP
            MsgBox("Valid  Entry.")
        Else
            MsgBox("inValid  Entry.")
        End If
Avatar of Jorge Paulino

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
   myArray.Add(YourValue)
End While

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

myArray = Nothing