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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:47:33+00:00 2026-05-10T22:47:33+00:00

I’m calling the code below. On the line (IDataReader dr = cmd.ExecuteReader()) sql barfs

  • 0

I’m calling the code below.

On the line (IDataReader dr = cmd.ExecuteReader()) sql barfs with an Incorrect syntax near ‘CompanyUpdate’.

   using (SqlCommand cmd = new SqlCommand('CompanyUpdate'))         {             cmd.Parameters.Add('@CompanyID',SqlDbType.Int);             cmd.Parameters.Add('@Description',SqlDbType.VarChar,50);             cmd.Parameters['@CompanyID'].Value = companyid;             cmd.Parameters['@Description'].Value = description;              SqlConnection cn = new SqlConnection('Data Source=[datasource];Initial Catalog=dotNext;User ID=[user];Password=[password];Pooling=True;Application Name=dotNext');             cn.Open();             cmd.Connection = cn;             using (IDataReader dr = cmd.ExecuteReader())             {                 if (dr.Read())                 {                     this.CompanyID = dr.GetInt32(0);                 }             }         } 

I had a look at sqlprofiler and noticed the following:

exec sp_executesql N'CompanyUpdate',N'@CompanyID int,@Description varchar(50)',@CompanyID=56,@Description='APC' 

Its wrapping my command wit a sp_executesql. All my other sql commands are just executed with no issues.

So my question is two fold: 1. Why is it using sp_executesql? 2. What am I doing wrong?

Details: sql2005, c#, vs2005

  • 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. 2026-05-10T22:47:33+00:00Added an answer on May 10, 2026 at 10:47 pm

    I notice that you’ve not set the CommandType to StoredProcedure… I don’t know if that’s the cause of your problem or not:

    cmd.CommandType = CommandType.StoredProcedure; 

    I’ve done this so many times myself I can’t count.

    Tip to trigger your memory when this throws exceptions next time:

    Have SQL Query Profiler open while you’re running your app. When each command executes, it shows the SQL generated and run on the server side. If the SQL generated begins with sp_executesql followed by your query then it’s being run as a regular query – i.e. cmd.CommandType = CommandType.Text, if it starts with exec, chances are it’s run as a stored proc. Make sure you’re getting the correct SQL generated for the type of query you’re trying to run.

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

Sidebar

Ask A Question

Stats

  • Questions 88k
  • Answers 88k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you try to raise an error that's not of… May 11, 2026 at 5:46 pm
  • Editorial Team
    Editorial Team added an answer Simply, you define an interface for the operations you want… May 11, 2026 at 5:46 pm
  • Editorial Team
    Editorial Team added an answer This is described in detail in Effective Java as Item… May 11, 2026 at 5:46 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.