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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:04:06+00:00 2026-05-30T19:04:06+00:00

Hello I’m running into an error for my update function to a SQL database

  • 0

Hello I’m running into an error for my update function to a SQL database table. The error is:

Error: Operand type clash: text is incompatible with smallint

And I have no idea what is wrong there should be no values of type int anywhere. All the inputs are strings and the table column type are all text. The update function is this:

    public static void UpdateRows(string table, string columnToGet, string columnValueGet, string columnToSet, string columnValueToSet)
{
   try
   {
   SqlConnection connection = new SqlConnection(Global.connectionString);
   string updateString = "UPDATE " + table + " " + "SET " + columnToSet + "=" + columnValueToSet + " WHERE " + columnToGet + "=" + columnValueGet;
   Console.WriteLine(updateString);

   using (SqlCommand cmd = new SqlCommand(updateString, connection))
   {
         connection.Open();
         cmd.Parameters.AddWithValue("@" + columnToSet, "'" + columnValueToSet + "'");
         cmd.Parameters.AddWithValue("@" + columnToGet, "'" + columnValueGet + "'");

         cmd.ExecuteNonQuery();
         connection.Close();
    }

}
catch (SqlException ex)
{
    Console.WriteLine("Error: " + ex.Message);
    throw;
}
}

The console outputs a string like this :

UPDATE parentDirectory SET Child1ID=50042 WHERE ParentID=10020

And then the error appears. What is wrong? I’ve tried added “‘” characters for the value variables, then I get a different error. I’ve got my Insert function sort of in the same format somewhere else and it works fine. Please help.

  • 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-30T19:04:08+00:00Added an answer on May 30, 2026 at 7:04 pm

    The column name should not be a parameter. By having the parameter include the column name columnValueToSet gets treated as a number. PS: this looks like a fishy design.
    PPS: it also opens it up to SQL injection.

    public static void UpdateRows(string table, string columnToGet,
                 string columnValueGet, string columnToSet, string columnValueToSet)
    {
        try
        {
            SqlConnection connection = new SqlConnection(Global.connectionString);
            string updateString =
                       "UPDATE " + table + " " +
                       "SET " + columnToSet   + "= @columnValueToSet " + 
                       "WHERE " + columnToGet + "= @columnValueGet;";
            Console.WriteLine(updateString);
    
            using (SqlCommand cmd = new SqlCommand(updateString, connection))
            {
                connection.Open();
                cmd.Parameters.AddWithValue("@columnValueToSet", columnValueToSet);
                cmd.Parameters.Add("@columnValueGet", SqlDbType.Text).Value= columnValueGet;
                cmd.ExecuteNonQuery();
                connection.Close();
            }
        }
        catch (SqlException ex)
        {
            Console.WriteLine("Error: " + ex.Message);
            throw;
        }
     }
    

    EDIT: As GarethD pointed out, the key problem is that parentId is defined as Text and there’s no conversion between Text and int (there is between varchar and int, but not Text and int).

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

Sidebar

Related Questions

hello im am getting JS error : Uncaught SyntaxError: Unexpected identifier here <script type=text/javascript>
Hello we have an SQL server application running over a low bandwith connection. We
Hello I wrote an application and while deploying shows error in line mCamera=Camera.open(); Where
Hello Guys I am trying to figure out why i am gettings this error
Hello i´m trying to set info from a post method into a variable that
Hello guys i have set background image on my input text and text area
Hello I want to convert a PDF file to text file. I am converting
Hello guys I am working on silverlight and I have issue regarding on database
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello I'm developing a webapp and i'm about to design the database, i came

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.