需要帮助减去数据库列中的值

时间:2022-08-25 02:09:02

I am trying to minus value in database column from textbox I got error an expression of non-boolean type specified in a context where condition is expected

我试图从文本框中减去数据库列中的值我得到错误在预期条件的上下文中指定的非布尔类型的表达式

  cn.Open();
  SqlCommand command = new SqlCommand();
  command.Connection = cn;

  command.CommandText = "select * from class where  quanitity - '"+Convert.ToInt32(textBox10.Text)+"'";
  command.ExecuteNonQuery();

  cn.Close();

4 个解决方案

#1


2  

You are not minus value to column.you want like this

你不是列的负值。你想要这样

        command.CommandText = "update class set quanitity = quanitity - "+Convert.ToInt32(textBox10.Text) ;

#2


2  

This will definitely work

这肯定会奏效

command.CommandText = string.Format("update class set quanitity= quanitity - {0}",Convert.ToInt32(textBox10.Text));

#3


0  

You need a value to compare your two numbers to. You are subtracting your TextBox10 value from quantity, but what result set do you want to see after subtracting the value? There needs to be a comparison somewhere to the right of your WHERE.

您需要一个值来比较您的两个数字。您是从数量中减去TextBox10值,但是在减去该值后,您希望看到哪个结果集?需要在WHERE的右侧进行比较。

command.CommandText = "select (quantity - "+Convert.ToInt32(textBox10.Text)+") from class ;

#4


0  

I suspect you SQL Injection alert..Do not Concatenate string it's wide open for sql injection alert.So use parameterized query

我怀疑你的SQL注入警告..不要连接字符串它是广泛开放的sql注入alert.So使用参数化查询

command.CommandText = "select * from class where  quanitity -@txtbox10";
command.Parameters.AddWithValue("@txtbox10", Convert.ToInt32(textBox10.Text));
command.ExecuteNonQuery();

#1


2  

You are not minus value to column.you want like this

你不是列的负值。你想要这样

        command.CommandText = "update class set quanitity = quanitity - "+Convert.ToInt32(textBox10.Text) ;

#2


2  

This will definitely work

这肯定会奏效

command.CommandText = string.Format("update class set quanitity= quanitity - {0}",Convert.ToInt32(textBox10.Text));

#3


0  

You need a value to compare your two numbers to. You are subtracting your TextBox10 value from quantity, but what result set do you want to see after subtracting the value? There needs to be a comparison somewhere to the right of your WHERE.

您需要一个值来比较您的两个数字。您是从数量中减去TextBox10值,但是在减去该值后,您希望看到哪个结果集?需要在WHERE的右侧进行比较。

command.CommandText = "select (quantity - "+Convert.ToInt32(textBox10.Text)+") from class ;

#4


0  

I suspect you SQL Injection alert..Do not Concatenate string it's wide open for sql injection alert.So use parameterized query

我怀疑你的SQL注入警告..不要连接字符串它是广泛开放的sql注入alert.So使用参数化查询

command.CommandText = "select * from class where  quanitity -@txtbox10";
command.Parameters.AddWithValue("@txtbox10", Convert.ToInt32(textBox10.Text));
command.ExecuteNonQuery();