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

  • Home
  • SEARCH
  • 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 8202073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:02:36+00:00 2026-06-07T07:02:36+00:00

I get a specified cast not valid error when I execute a stored proc

  • 0

I get a specified cast not valid error when I execute a stored proc like this:

return (int)comm.ExecuteScalar();

When I execute it in SQL Server it returns 1, so I know my proc is working.

What is wrong with my cast?

Updated:

    public static int IsPresent(string userName, int inTime)
    {
        SqlConnection connObj = new SqlConnection();
        connObj.ConnectionString = Util.SQLConct();
        connObj.Open();

        SqlCommand comm = new SqlCommand("usp_IsUserLocked", connObj);

        comm.CommandType = CommandType.StoredProcedure;

        comm.Parameters.Add(new SqlParameter("@Username", userName));
        comm.Parameters.Add(new SqlParameter("@InTime", inTime));

        return (int)comm.ExecuteScalar();

    }

Thanks in advance

  • 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-07T07:02:38+00:00Added an answer on June 7, 2026 at 7:02 am

    It is possible that your method returns double or int64 or any other type which cannot be implicitly casted to (int). Use Convert.ToInt32 to ensure that your method returns the right type.

    using System;
    
    ...
    return Convert.ToInt32(comm.ExecuteScalar());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

fill error Specified cast is not valid if using : annual_leave_balance = (gaia ==
how to get a touch event only on specified view.Not on other view -(void)touchesEnded:(NSSet
If I can implicitly cast an integer value to a double, like: int a
I'm getting the following error when trying to get the sum in this Linq
I have this class... public class MyDTO { public int Id { get; set;
how to use google-maps on API2 to get navigation to specified place i've add
I want to get the system icon of a specified folder, but maybe the
I tried to get my application run at a specified time but I can't
I'm trying to get all the sublists that don't inherit from a specified class
I want user to wait for specified time(4seconds) to get connected to server. If

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.