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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:16:54+00:00 2026-05-25T15:16:54+00:00

I have an integer column in my table in the database, and I want

  • 0

I have an integer column in my table in the database, and I want to select it but it give me exception that can’t convert from int to string

Example I want to select CategoryID from Category table where CategoryName="Cat"

categoryID is int & categoryName is string

my linq query which I tried

string Category_ID = (from p in StaticVa.new_data_context.Categories
                              where p.CategoryName == Category_Name
                              select p.CategoryID).ToString();

It returned "SELECT [t0].[CategoryID]\r\nFROM [dbo].[Category] AS [t0]\r\nWHERE [t0].[CategoryName] = @p0\r\n"

  • 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-25T15:16:55+00:00Added an answer on May 25, 2026 at 3:16 pm

    try

    int Category_ID = (from p in StaticVa.new_data_context.Categories
                                  where p.CategoryName == Category_Name
                                  select p.CategoryID).FirstOrDefault();
    

    LINQ is trying to return a IQueryable of every id which matches the where clause, if you only want one you need to specify it as single or first

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

Sidebar

Related Questions

I have a database table that has a SortOrder integer column. In the UI
I have a table in a MySQL database from which I want to select
I have an integer column and I want to find numbers that start with
I have a Database table that I want to display in a DataGridView. However,
OK, I have a table with no natural key, only an integer identity column
I have a varchar(100) column in a table that contains a mix of integers
I have an Sqlite database in which I want to select rows of which
i want to store an array of integer values in a SQL database table
I have a stored procedure in my database that takes a table value parameter,
I have items in my database schema that are an integer and are set

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.