[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2007-08-11
Medium Priority
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

clockwatcher earned 2000 total points
ID: 19677893

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

Expert Comment

ID: 19678668
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

ID: 19678886

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

867 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