zoukankan      html  css  js  c++  java
  • Linq 完成搜索功能的两种写法~

            protected void Button1_Click(object sender, EventArgs e)
            {
               
     NorthWindDataContext db = new NorthWindDataContext();
                var search = from i in db.InBill
                             
    //  where SqlMethods.Like(i.SaleName, "%" + this.TextBox1.Text.Trim() + "%")
                             where i.SaleName.Contains(this.TextBox1.Text)   //对象是否在此字符串中出现
                             select i;

                GridView1.DataSource 
    = search;
                GridView1.DataBind();
            }

    第一种就是SqlMethods.Like()查询,需引用 System.Data.Linq.SqlClient; 

    第二种就是直接字段名.Contains(); 只需要引用 System.Linq

    还有一个问题我想问一下,这两种写法安全吗? 代码中那么写,会不会发生SQL注入?

  • 相关阅读:
    使用CSVDE批量导入命令/出口AD用户
    Everything You Wanted to Know About Machine Learning
    android Vibrator 用法
    oc-25- @property @synthesize
    oc-24-点语法
    oc-23-static
    oc-22-sel
    oc-21-class对象
    oc-20-多态
    oc-19-成员变量修饰符
  • 原文地址:https://www.cnblogs.com/zhuiyi/p/2064777.html
Copyright © 2011-2022 走看看