Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4332684
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:17:26+00:00 2026-05-21T10:17:26+00:00

What is the best way to compare an Int entry from a table in

  • 0

What is the best way to compare an Int entry from a table in a case statement?

Using SQL server 2008 R2, Visual Basic Express with LINQ to SQL.

The code I tried doesnt work:

Private Sub UpdateSetOpt()

    Dim db = New ACEDataContext
    Dim SRM = From q In db.Settings
              Where q.SettingID = frmMain.CurrentSID
              Select q.RollMethod

    Select Case SRM
        Case 1
            rbStandard.Checked = True
        Case 2
            rbProfession.Checked = True
        Case 3
            rbSpecies.Checked = True
        Case 4
            rbRandom.Checked = True
        Case Else
            rbStandard.Checked = False
            rbProfession.Checked = False
            rbSpecies.Checked = False
            rbRandom.Checked = False
    End Select

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T10:17:27+00:00Added an answer on May 21, 2026 at 10:17 am

    SRM isn’t an Integer since your From query returns a collection of items. To get just the first, use Single():

    Dim SRM = (From q In db.Settings
               Where q.SettingID = frmMain.CurrentSID
               Select q.RollMethod).Single()
    

    If the query actually returns more than a single value the above code will fail; you need to use First instead of Single then. Both will fail if no value is returned by the query. In that case, FirstOrDefault may be used instead (but probably isn’t appropriate in your situation).

    Adding to that, your Select Case is a sign of code smell. You should rather create an array of all the check boxes and use the integer to map into it:

    Dim checks As CheckBox() = New CheckBox() { _
        rbStandard, rbProfession, rbSpecies, rbRandom }
    
    ' Unset all checkboxes:
    For Each check In checks
        check.Checked = False
    End For
    
    If SRM > 0 AndAlso SRM <= checks.Length Then
        checks(SRM - 1).Checked = True
    End If
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

what is the best way to compare int arrays b and c with a:
What's the best way in code to compare enum values? For example, if I
The best way of describing this is I have a table of people with
Possible Duplicate: Best way to stop SQL Injection in PHP If I were to
I want to know the best way to compare two objects and to find
What's the best way to compare a Java date with Javascript date for greater
I'm wondering what the correct way to compare two characters ignoring case that will
What is the best way to compare std::string s? The obvious way would be
what is the best way to compare two objects and find the differences? Customer
What would be the best way to compare two date in java? Right now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.