using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;public partial class PriceUserControl : System.Web.UI.UserControl
{
    private string labelText;
    private string connectionString;
    private GridView resultGridView;
    private string tableName;
    private string columCondition;
    private string errorMessage;
    public string LabelText
    {
        set
        {
            this.labelText = value;
        }
        get
        {
            return this.labelText;
        }
    }
    public string ConnectionString
    {
        set
        {
            this.connectionString = value;
        }
        get
        {
            return this.connectionString;
        }
    }
    public GridView ResultGridView
    {
        set
        {
            resultGridView = value;
        }
        get
        {
            return this.resultGridView;
        }
    }
    public string TableName
    {
        set
        {
            this.tableName = value;
        }
        get
        {
            return this.tableName;
        }
    }
    public string ColumCondition
    {
        set
        {
            this.columCondition = value;
        }
        get
        {
            return this.columCondition;
        }
     }
    protected void Page_Load(object sender, EventArgs e)
    {
        this.ColumsName.Text = this.labelText;
    }
    private DataTable SearchResult()
    {
        try
        {
            System.Data.OleDb.OleDbConnection conn = new OleDbConnection(connectionString);
            conn.Open();
            string sqlString = "select * from" + tableName + "where" + columCondition + "like  '%" + this.Conditon.Text.ToString() + "%'";
            System.Data.OleDb.OleDbDataAdapter ada = new OleDbDataAdapter(sqlString, conn);
           //ada.SelectCommand = new OleDbCommand(sqlString,conn);
            System.Data.DataTable dataTable = new DataTable();
            ada.Fill(dataTable);
            conn.Close();
            return dataTable;
        }
        catch (Exception e)
        {
            errorMessage = "访问数据库失败,请检测数据库连接!";
            return null;
        }
    }
    protected void Btn_Search_Click(object sender, EventArgs e)
    {
        resultGridView.DataSource = SearchResult().DefaultView;
        resultGridView.DataBind();
    }
}