如题。有个SQL的查询语句
比如,用来查询数据库中名称包含“就”字的书籍信息,
select * from BookInfo where BookName like '%就%',现在我想把它改到winform中,用textbox来输入这个要包含的字,请问怎么写?我调了半天括号引号百分号,总是调不好,
求达人给个正确无误的句子

解决方案 »

  1.   

    string cmdtext=@"select * from BookInfo where BookName like '%"+textbox1.Text.ToString()+"%',";
      

  2.   


    string cmdtext =
     @"select * from BookInfo where BookName like '%" + textBox1.Text.ToString() + "%'";string cmdtext = @"select * from BookInfo where BookName like '%" + textBox1.Text.ToString() + "%'";
      

  3.   

    string text = string.Format("select * from BookInfo where BookName like '%{0}%'",textBox1.Text.Trim());
      

  4.   


    用参数形式:
    string sSQL = "select * from BookInfo where BookName like '%@BName%'";
    SqlParameter[] arrParm = new SqlParameter[1];
    arrParm[0] = new SqlParameter("@BName", "文本框的值");
      

  5.   

    一般的话就是这样的
    string s=select * from BookInfo where BookName like '%"+this.TextBox1.Text+"%'"
    然后执行这句sql不过如果TextBox1.Text里面带有单引号的话,如:TextBox1.Text="aabb'cdew";
    这样的话,执行s就会出错,这样的解决方法就是用参数
    方法就是5楼的方法
      

  6.   

    写错了一点点,掉了个前双引号,语句以分号结尾
    string s="select * from BookInfo where BookName like '%"+this.TextBox1.Text+"%'"
    ;
      

  7.   

    string cmdtext=@"select * from BookInfo where BookName like '%"+textbox1.Text.ToString()+"%'";