请问由一个course表,里面有学生姓名属性
在vb。net中,怎么用一文本框读取输入的值然。比如str = TextBox1.Text
     Dim sqlString As String = "select * from course where id="     '后面应该怎么写

解决方案 »

  1.   

    select * from course where id=@id
    然后用parameters集合,给相应的参数赋值就行了。sqlcommand.parameters.add(new parameter("@id",...))
      

  2.   


    str = TextBox1.Text 
    Dim sqlString As String = "select * from course where id=" +str ;
      

  3.   

    "select * from course where id=" +str ;
      

  4.   


    str = TextBox1.Text
    Dim sqlString As String = "select * from course where id='" +TextBox1.Text .tostring.trim.replace("'","''")+"'"
    最安全的,一定要加上replace ’的语句,不然到时候如果有特殊字符就死定了
      

  5.   


    不对啊
    不如我要查询张的人 
    sql语句是 Dim sqlString As String = "select * from course where id= '张一 '"可是你那么写我调试的时候发现语句是 Dim sqlString As String = "select * from course where id= 张一 "  没有了''
      

  6.   


    支持 2 楼的参数化。不要用拼接语句,会导致 SQL 注入。