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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:48:58+00:00 2026-06-15T06:48:58+00:00

I want to get single value from select query called tenant. Tenant_Facing from SQL

  • 0

I want to get single value from select query called tenant. Tenant_Facing from SQL Server have single char value that either ‘Y’ or ‘N’. When I execute it, there a error that say “Specified cast is not valid” on Char tenant = (Char)cmd.ExecuteScalar();.
I don’t understand why it not match even they are both Char? Here my codes,

protected void DropDownArchitecture_SelectedIndexChanged(object sender, EventArgs e)
    {

        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Database_Shared_NotebookConnectionString"].ConnectionString);

        string architecture = ((DropDownList)GridViewServer.FooterRow.FindControl("DropDownArchitecture")).Text;

        SqlCommand cmd = new SqlCommand("SELECT Tenant_Facing FROM tblArchitecture WHERE Architecture = '" + architecture + "'");

        cmd.Connection = conn;

        conn.Open();

        Char tenant = (Char)cmd.ExecuteScalar();

        conn.Close();

        if (tenant == 'Y')
        {
            ((DropDownList)GridViewServer.FooterRow.FindControl("DropDownTenant")).Visible = true;
        }
        else
        {
            ((DropDownList)GridViewServer.FooterRow.FindControl("DropDownTenant")).Visible = false;
        }
    }
  • 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-15T06:49:00+00:00Added an answer on June 15, 2026 at 6:49 am

    Even though your data type in SQL Server is a single char, that type still maps to string in ADO.NET. Try it like this instead:

    string tenant = (string)cmd.ExecuteScalar();
    
    conn.Close();
    
    if (tenant == "Y")
    //            ^ ^ make sure to change these to double-quotes
    {
        ((DropDownList)GridViewServer.FooterRow.FindControl("DropDownTenant")).Visible = true;
    }
    else
    {
        ((DropDownList)GridViewServer.FooterRow.FindControl("DropDownTenant")).Visible = false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a List<List> . I want to get a single List from that.
I am using the following query to return a single value: select er.elig_code from
Consider I have such SQL query: SELECT t1.* FROM table1 t1 LEFT JOIN table2
I want to get rows from database. I am using the following query: select
I want to get the single digits from two digits.for example if 36 I
I want to get data from two tables with single Entity class. How?? public
Basically I want get data I already have accessed from javascript and passing it
I have a SQL query that I'm currently solving by doing two queries. I
I have a query that is meant to return user details from Wordpress tables.
This is my query to get model information from one table and a single

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.