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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:38:38+00:00 2026-06-04T07:38:38+00:00

When I attempt to execute the following non query sql command in my application

  • 0

When I attempt to execute the following non query sql command in my application I always get the error message –

Must declare the scalar variable ‘@RateID’

I’m a bit at a loss as to why I receive this error. Here is my code:

string sqlText = "INSERT INTO tblRates (RateID, IPName, RateName, Rate, DateFrom, DateTo, Active) " +
                 "VALUES (@RateID, @IPName, @RateName, @Rate, @DateFrom, @DateTo, @Active);";

SqlCommand sqlCom = new SqlCommand(sqlText);
sqlCom.Parameters.Add("@RateID", SqlDbType.Int);
sqlCom.Parameters.Add("@IPName", SqlDbType.Text);
sqlCom.Parameters.Add("@RateName", SqlDbType.Text);
sqlCom.Parameters.Add("@Rate", SqlDbType.Decimal);
sqlCom.Parameters.Add("@DateFrom", SqlDbType.Date);
sqlCom.Parameters.Add("@DateTo", SqlDbType.Date);
sqlCom.Parameters.Add("@Active", SqlDbType.Bit);

this._rateID = NextID();

sqlCom.Parameters["@RateID"].Value = this._rateID;

if (this._ipName == "All")
{
   sqlCom.Parameters["@IPName"].Value = DBNull.Value;
}
else
{
   sqlCom.Parameters["@IPName"].Value = this._ipName;
}

sqlCom.Parameters["@RateName"].Value = this._rateName;
sqlCom.Parameters["@Rate"].Value = this._rate;
sqlCom.Parameters["@DateFrom"].Value = this._dateFrom;
sqlCom.Parameters["@DateTo"].Value = this._dateTo;

this._active = true;
sqlCom.Parameters["@Active"].Value = this._active;

cSqlQuery cQ = new cSqlQuery(sqlText, "non query");

When I step through line by line, I see the parameter @RateID is successfully added to the sqlCommand object, the method NextID correctly returns an integer value which is accepted as the Value of the @RateID parameter, but when I execute non query on the SqlCommand I get the aforementioned error.

Any help much be much appreciated.

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

    You’re setting up the sqlCom object – and the code looks fine.

    But then: it seems you’re just executing the SQL command here:

    cSqlQuery cQ = new cSqlQuery(sqlText, "non query");
    

    not using all that setup code you had before! Why?

    The parameters and all are contained in the sqlCom object – but your cSqlQuery doesn’t seem to actually look at that object – just the SQL statement itself…

    What happens if you use this line instead:

    sqlCom.ExecuteNonQuery();
    

    Does this work without exception?

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

Sidebar

Related Questions

I want to execute following query: from Item i where i.categoryItems.catalogId = :catId That
Greetings, I'm having the following issue: When I attempt to execute several INSERT INTO
I want to execute the following shell command in emacs-lisp: ls -t ~/org *.txt
I'm attempting to execute the following bash command on some images using Ruby: class
when i execute dtsx package through command line i am triggered with the following
I am trying to execute a OS command through C#. I have the following
When I attempt to debug a simple program with gdb on cygwin I get
When I execute the following: INSERT ALL INTO table@database_link(columnName) VALUES (columnValue) SELECT columnValue FROM
I'm getting the following error when using the multiprocessing module within a python daemon
No matter what i attempt i keep getting the following exception being thrown by

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.