1.这样可以:
command.CommandText = @"Update college Set name='mick' where ID=" + textBox3.Text;2.这样却不行:
command.CommandText = @"Update college Set name=" + textBox1.Text + @"where ID=" + textBox3.Text;
错误信息:
未处理的“System.Data.OleDb.OleDbException”类型的异常出现在 System.Data.dll 中。
其他信息: 语法错误 (操作符丢失) 在查询表达式 'mickwhere ID=1' 中。3.这样仍然不行:(where前面加了个空格)
command.CommandText = @"Update college Set name= " + textBox1.Text + @" where ID=" + textBox3.Text;
错误信息:
未处理的“System.Data.OleDb.OleDbException”类型的异常出现在 System.Data.dll 中。
其他信息: 至少一个参数没有被指定值。请问应如何处理?
急 多谢!!!!

解决方案 »

  1.   

    command.CommandText = @"Update college Set name= '" + textBox1.Text + @"' where ID=" + textBox3.Text;
      

  2.   

    2.这样却不行:
    command.CommandText = @"Update college Set name=" + textBox1.Text + @"where ID=" + textBox3.Text;
    错误信息:
    未处理的“System.Data.OleDb.OleDbException”类型的异常出现在 System.Data.dll 中。
    其他信息: 语法错误 (操作符丢失) 在查询表达式 'mickwhere ID=1' 中。 
    说的很清楚了, 语法错误    name='" + textBox1.Text + "' where ID="  where前面加空格,text内容用引号
      

  3.   

    textBox1.Text 字符串前后加 单引号:command.CommandText = @"Update college Set name= '" + textBox1.Text + @"' where ID=" + textBox3.Text; 
      

  4.   

    这样写不容易出错,,你试试
    command.CommandText = string.Format("Update college Set name='{0}' where ID={1}",textBox1.Tex,textBox3.Tex)
      

  5.   

    command.CommandText = "Update college Set name='" + textBox1.Text + "' where ID=" + int.Parse(textBox3.Text);
      

  6.   


    command.CommandText = @"Update college Set name=" + textBox1.Text + @"where ID=" + textBox3.Text; 
    在数据库中这个字段是字符类型的,所以要加'
    如下:
    command.CommandText = @"Update college Set name='" + textBox1.Text + @"' where ID=" + textBox3.Text; 这样估计OK的。
      

  7.   

    command.CommandText = @"Update college Set name='" + textBox1.Text + "' where ID=" + textBox3.Text"; 
      

  8.   

    上面写错了
    command.CommandText = @"Update college Set name='" + textBox1.Text + "' where ID=" + textBox3.Text+";
      

  9.   

    用SQL语句操作数据库的时候,要注意字段的类型
    如果是文本类型,注意在变量前后都要加上单引号 
    如果是数字类型,就不必加单引号
    这就是为什么你1可以,2,3不行的原因。