日期:2014-05-20 浏览次数:21788 次
private void btn_Search_Click(object sender, EventArgs e)
{
string sql = GetCondition();
DataTable dt=PubData.GetData(sql);
//显示方式
SetDataGridViewStyle();
dataGridView1.DataSource = dt;
}
/// <summary>
/// 拼接条件
/// </summary>
/// <returns></returns>
private string GetCondition()
{
StringBuilder sb = new StringBuilder();
sb.Append("select BookName,Author,Press,Qty,Status From BookInfo where");
sb.Append(" BookName like '%"+txt_BookName.Text.Trim()+"%'");
sb.Append(" and Author like '%"+txt_Author.Text.Trim()+"%'");
sb.Append(" and Press like '%"+txt_Press.Text.Trim()+"%'");
return sb.ToString();
}
/// <summary>
/// 设置DataGridView列
/// </summary>
private void SetDataGridViewStyle()
{
DataGridViewTextBoxColumn columns = new DataGridViewTextBoxColumn();
columns.Name = "BookName";
columns.HeaderText = "书籍名称";
columns.DataPropertyName = "BookName";
columns.Width = 100;
this.dataGridView1.Columns.Add(columns);
columns = new DataGridViewTextBoxColumn();
columns.Name = "Author";
columns.HeaderText = "作者";