标题:c#模糊查询出错
只看楼主
lukebc
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:3
帖 子:74
专家分:32
注 册:2009-8-18
结帖率:71.43%
 问题点数:0 回复次数:1 
c#模糊查询出错
SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "server=LUKE\\SQLEXPRESS;uid=sa;pwd=sa;database=luke";
            conn.Open();
            DataTable dt = new DataTable("resouce");
            dt.Clear();
            SqlDataAdapter adp = new SqlDataAdapter("select * from text1", conn);
            adp.Fill(dt);
            string sql = "select * from text1 where bh like %"+textBox1.Text+"%";
            SqlCommand command = new SqlCommand(sql, conn);
            SqlDataAdapter ad = new SqlDataAdapter();
            ad.SelectCommand = command;
            ad.Fill(dt);
            dt.Clear();
            dataGridView1.DataSource = dt.DefaultView;
我在textbox1中输入查询数字 2 提示出错   
2016-08-29 13:32
over1230
Rank: 8Rank: 8
等 级:贵宾
威 望:25
帖 子:113
专家分:897
注 册:2009-10-9
得分:0 
string sql = "select * from text1 where bh like '%"+textBox1.Text+"%'";
2016-08-29 13:46



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-468266-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012945 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved