本帖最后由 wanghaibo8746 于 2012-12-16 13:27:22 编辑

解决方案 »

  1.   

    一般在设计系统时用到ORM映射关系,其实在UI层将对应的字段放到Model类中这样只要将参数传入数据处理层即可返回执行结果
    eg:  姓名: txtName 编号:txtId 年龄:txtAge
    PeopleModel model =new PeopleModel()
    model.Name =txtName.text;
    model.Id =txtId.text;
    model.Age =txtAge.text;
     
    将这个Model传给数据处理层,典型的三层做法。
      

  2.   

    private void button2_Click(object sender, EventArgs e)
            {
                SqlConnection connection = new SqlConnection("Data Source=.;Initial Catalog=DataBase;User ID=sa;password=sa");
                DataTable dt = new DataTable();
                //查询语句
                string sql = "SELECT * FROM 表名 WHERE " + label1.Text.Trim() + " ='" + textBox1.Text.Trim().ToString() + "'";
                connection.Open();
                DataSet ds = new DataSet();
                SqlCommand cmd = new SqlCommand(sql, connection);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(ds);
                dt = ds.Tables[0];            dataGridView1.DataSource = dt;
                
            }
    是这样吗?
      

  3.   

    数据从哪里来?
    sql数据库
    那怎么查数据?
    sql语句?
    那前台的条件怎么传入sql?
    拼sql语句select * from table where id = 前台的textbox.text
      

  4.   


    if(!string.IsNullOrEmpty(textbox1.text.trim()))
    {
         sql拼接;
    }
    if(!string.IsNullOrEmpty(textbox2.text.trim()))
    {
         sql拼接;
    }