我在三层中感到困惑 没有使用3层这个功能工作
DataTable dt;
private void textBox1_TextChanged(object sender, EventArgs e)
{
DataView dv = new DataView(dt);
dv.RowFilter = string.Format("emp_f_name LIKE '%{0}%'",textBox1.Text);
dataGridView1.DataSource = dv;
}
3层中的BUt 我很困惑,你们可以帮助我重写我试图在文本框中搜索名字的代码
在我的bll课程中
public DataTable Display(string fname)
{
try
{
return obj.Display(fname);
}
catch (Exception ex)
{
throw ex;
}
}
在我的dal课程中
public DataTable Display(string fname)
{
string query2;
OpenCnn();
query2 = "SELECT * FROM cntc_employee where fname='" +fname + "' ";
sda = new SqlDataAdapter(query2, con);
dt = new DataTable();
sda.Fill(dt);
CloseCnn();
return dt;
}
班级
private void textBox1_TextChanged(object sender, EventArgs e)
{
string fname = txtfname.Text;
DataView dv = new DataView(dt);
dt = obj.Display(fname);
dv.RowFilter = string.Format("emp_f_name LIKE '%{0}%'", textBox1.Text);
dataGridView1.DataSource = dv;
this.dataGridView1.DataSource = obj.Display(this.txtfname.Text);
}
答案 0 :(得分:1)
public DataTable Display(string fname)
{
try
{
DataTable dt = obj.Display(fname);//call to DAL
DataView dv = new DataView(dt);
dv.RowFilter = string.Format("emp_f_name LIKE '%{0}%'",
textBox1.Text);
return dv.ToTable();
}
catch (Exception ex)
{
throw ex;
}
}
在你的用户界面
private void textBox1_TextChanged(object sender, EventArgs e)
{
string fname = txtfname.Text;
dt = obj.Display(fname);// Call to BLL
dataGridView1.DataSource = dt;
}
在你的DAL课程中
public DataTable Display(string fname)
{
string query2;
OpenCnn();
query2 = "SELECT * FROM cntc_employee where fname='" +fname + "' ";
sda = new SqlDataAdapter(query2, con);
dt = new DataTable();
sda.Fill(dt);
CloseCnn();
return dt;
}