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 8035873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:26:17+00:00 2026-06-05T02:26:17+00:00

I am trying to use a C# SQL search and then get a Boolean

  • 0

I am trying to use a C# SQL search and then get a Boolean result on whether or not the item was found. I have the search statement working but not the Boolean result portion.

EX: If i have a table with a column called @Names with the names, A,B,C but i search for Name D, how or can i get a Boolean result to come back and save false in a Boolean variable.

  • 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-06-05T02:26:19+00:00Added an answer on June 5, 2026 at 2:26 am

    You can try this approach:

    string query = @"
    select case when exists (
        select 1
        from MyTable
        where Name='D' -- This is the condition you are checking
    ) then 1 else 0 end";
    
    bool exists;
    using(var command = new SqlCommand(query, connection))
    {
         exists = Convert.ToBoolean(command.ExecuteScaler());
    }
    

    You can now use the ExecuteScalar method, and cast the result to bool for the result of your query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this sql query where I'm trying to use CONTAINS to search the
Trying to use Linq to SQL for a small project I'm working on at
Trying to use: :On Error exit :r D:\opt\db_objects\REPORTS\dbo.sp_ReportCountLORUsers.sql ...and I get: Msg 102, Level
I'm trying to use Linq to SQL to search a text column for multiple
I'm a sql noob trying to get this query to use 2 tables. tables
I'm trying to use SQL Server Profiler (2005) to track down some application performance
I am trying to use a SQL Server 2008 Ranking Function on a query
I'm trying to use LINQ to SQL to select a few specific columns from
I'm trying to use linq to sql for my project (very short deadline), and
I'm trying to use LINQ to SQL Server in C#/.NET on Visual Studio 2010.

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.