关于C#模糊查询结果无法显示
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication9
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
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 ="";
if (textBox1.Text == ""&& textBox2.Text=="")
{
sql = "select * from text1";
label1.Text = sql;
}
else
{
sql = "select * from text1 where bh like '%" + textBox1.Text + "%'";
label1.Text = sql;
}
SqlCommand command = new SqlCommand(sql, conn);
SqlDataAdapter ad = new SqlDataAdapter();
ad.SelectCommand = command;
ad.Fill(dt);
dt.Clear();
dataGridView1.DataSource = dt.DefaultView;
}
查询的结果为空白
当把第二个 dt.clear() 去掉后,可查询但其它内容也无法清空,结果不断累计,不清屏
不知道怎么改