c#vs2015 一个文本框多字段模糊查询datagridview表数据



c#vs2015 一个文本框多字段模糊查询datagridview表数据_第1张图片c#vs2015 一个文本框多字段模糊查询datagridview表数据_第2张图片c#vs2015 一个文本框多字段模糊查询datagridview表数据_第3张图片c#vs2015 一个文本框多字段模糊查询datagridview表数据_第4张图片c#vs2015 一个文本框多字段模糊查询datagridview表数据_第5张图片using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 一个本框多字段查询
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void dataGridViewAssignmentERP1()//dataGridView1表,改列名称,将控件设置为只读,排序, 宽度
        {
            dataGridView1.Columns[0].HeaderText = "选择";//改列名称
            dataGridView1.Columns[1].HeaderText = "员工编号";//改列名称
            dataGridView1.Columns[2].HeaderText = "员工姓名"; //改列名称
            dataGridView1.Columns[3].HeaderText = "性别";//改列名称
            dataGridView1.Columns[4].HeaderText = "状态"; //改列名称
            dataGridView1.Columns[5].HeaderText = "部门";//改列名称
            dataGridView1.Columns[6].HeaderText = "职务"; //改列名称
            dataGridView1.Columns[7].HeaderText = "教育程度";//改列名称
            dataGridView1.Columns[8].HeaderText = "身份证号"; //改列名称
            dataGridView1.Columns[9].HeaderText = "电话号码";//改列名称
            dataGridView1.Columns[10].HeaderText = "籍贯"; //改列名称
            dataGridView1.Columns[11].HeaderText = "出生日期";//改列名称
            dataGridView1.Columns[12].HeaderText = "家庭电话"; //改列名称
            dataGridView1.Columns[13].HeaderText = "家住地址";//改列名称
            dataGridView1.Columns[14].HeaderText = "民族"; //改列名称
            dataGridView1.Columns[15].HeaderText = "婚姻状况";//改列名称
            dataGridView1.Columns[16].HeaderText = "现住地址"; //改列名称
            dataGridView1.Columns[17].HeaderText = "入职日期";//改列名称
            dataGridView1.Columns[18].HeaderText = "试用期"; //改列名称
            dataGridView1.Columns[19].HeaderText = "离职日期"; //改列名称
            dataGridView1.Columns[20].HeaderText = "政治面貌";//改列名称
            dataGridView1.Columns[21].HeaderText = "电子邮箱"; //改列名称
            dataGridView1.Columns[22].HeaderText = "毕业学校"; //改列名称
            dataGridView1.Columns[23].HeaderText = "所学专业"; //改列名称
            dataGridView1.Columns[24].HeaderText = "工资银行帐号";//改列名称
            dataGridView1.Columns[25].HeaderText = "备注"; //改列名称
        }
        SqlConnection conn;
        private void RefreshData1()//dataGridView1表刷新数据
        {
            try
            {
                conn = new SqlConnection("server=WINDOWS-CBBU2E6;database=OrderManagementSystem;Uid = sa; Pwd = 123");
                SqlCommand cmd = new SqlCommand("select*from dbo.staffinformation", conn);
                SqlDataAdapter sda = new SqlDataAdapter();
                sda.SelectCommand = cmd;
                DataSet ds = new DataSet();
                sda.Fill(ds, "dbo.staffinformation");
                dataGridView1.DataSource = ds.Tables["dbo.staffinformation"];
                dataGridViewAssignmentERP1();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                throw ex;
            }

        }
        private void Form1_Load(object sender, EventArgs e)
        {
            RefreshData1();//dataGridView1表刷新数据
        }

        private void button1_Click(object sender, EventArgs e)
        {
            conn = new SqlConnection("server=WINDOWS-CBBU2E6;database=OrderManagementSystem;Uid = sa; Pwd = 123");
            SqlCommand cmd = new SqlCommand("select * from dbo.staffinformation where  PersonnelID  like '%" + textBox1.Text + "%'or  PersonnelName  like '%" + textBox1.Text + "%' or  Sex  like '%" + textBox1.Text + "%'or  Status  like '%" + textBox1.Text + "%'or  Department  like '%" + textBox1.Text + "%'or  Post  like '%" + textBox1.Text + "%'or  EducationDegree  like '%" + textBox1.Text + "%'or  IDNumber  like '%" + textBox1.Text + "%'or  PhoneCode  like '%" + textBox1.Text + "%'or  NativePlace  like '%" + textBox1.Text + "%'or  BirthDate  like '%" + textBox1.Text + "%'or  HomePhone  like '%" + textBox1.Text + "%'or  HomeAddress   like '%" + textBox1.Text + "%'or  Nation  like '%" + textBox1.Text + "%'or  MaritalStatus  like '%" + textBox1.Text + "%'or  PresentAddress  like '%" + textBox1.Text + "%'or  EntryDate   like '%" + textBox1.Text + "%'or  DuringProbation  like '%" + textBox1.Text + "%'or  DimissionDate  like '%" + textBox1.Text + "%'or  PoliticalStatus  like '%" + textBox1.Text + "%'or  Email   like '%" + textBox1.Text + "%'or  SchoolGraduation  like '%" + textBox1.Text + "%'or  SoxtSpecialty  like '%" + textBox1.Text + "%'or  WagBankID   like '%" + textBox1.Text + "%'or  Remarks  like '%" + textBox1.Text + "%'", conn);
            SqlDataAdapter sda = new SqlDataAdapter();
            sda.SelectCommand = cmd;
            DataSet ds = new DataSet();
            sda.Fill(ds, "dbo.staffinformation");
            dataGridView1.DataSource = ds.Tables["dbo.staffinformation"];
        }
    }
}

你可能感兴趣的:(c#vs2015 一个文本框多字段模糊查询datagridview表数据)