• winform窗体简单查询功能


    1.【一个button txetbox listview】

    private void button_Click(object sender, EventArgs e)
    {
    SqlConnection scn = new SqlConnection(); //创建对象并设置属性
    scn.ConnectionString = "server=XZ-20130306TSYW\\SQL;trusted_connection=yes;database=查询;"; //连接字符串
    SqlCommand scmd = new SqlCommand(); // 创建并使用sqlCommand对象
    scmd.Connection = scn; // 命令对象名.Connection= 连接对象名
    DataSet ds = new DataSet(); //创建DataSet对象
    scn.Open(); //打开
    string strsql = string.Empty; //查询赋初值
    strsql = "select * from 表名 where 列名 like '%" + "列名" + "%'"; //查询
    scmd.CommandText = strsql;
    SqlDataAdapter sda = new SqlDataAdapter(scmd);
    sda.Fill(ds, "表名");
    DataTable dt = new DataTable();
    dt = ds.Tables[0];
    foreach (DataRow row in dt.Rows)
    {
    ListViewItem lsvItem = listView1.Items.Add(row["列名"].ToString());
    lsvItem.Tag = row;
    }

    2.【用一个textbox 和一个button,DataGirdview实现查询】
    代码如下:
    private void button_Click(object sender, EventArgs e)
    {
    DataSet ds = new DataSet();
    DataTable dt = new DataTable();
    SqlConnection scn = new SqlConnection();
    scn.ConnectionString = "server=XZ-20130306TSYW\\SQL;trusted_connection=yes;database=查询;";
    scn.Open();
    SqlCommand scmd = new SqlCommand();
    scmd.Connection = scn;
    string strsql = string.Empty;
    if (textBox1.Text.Trim() != "")
    {
    strsql = "select * from 新芒果大厦 where 网展公司 like '%" + textBox1.Text.Trim() + "%'";
    }
    else
    {

    }
    scmd.CommandText = strsql;

    SqlDataAdapter sda = new SqlDataAdapter(scmd);
    sda.Fill(ds, "新芒果大厦");
    dt = ds.Tables[0];
    dataGridView1.DataSource = dt;
    }

  • 相关阅读:
    mina 字节数组编解码器的写法 I
    latex编写论文
    HTML学习
    Apache Mina Filter
    静态循环队列的相关操作及详解
    hdu1242 Rescue(BFS +优先队列 or BFS )
    让我们区分质量保证与测试
    新玩的windows phone app studio
    Pylons安装苦逼之路
    [置顶] js 实现 <input type="file" /> 文件上传
  • 原文地址:https://www.cnblogs.com/zx724792526/p/2975415.html
Copyright © 2020-2023  润新知