zoukankan      html  css  js  c++  java
  • 关于gridview 实现查询功能的方法(转载)

    protected void btnSearch_Click(object sender, EventArgs e)
    {
    TestCon();
    }
    protected void btnAllData_Click(object sender, EventArgs e)
    {
    TestConAll();

    }
    private void TestConAllData()
    {
    string strConn = "data source=.;initial catalog=JLCallSystem;user id=sa;password=123456";

    SqlConnection con = new SqlConnection(strConn);
    DataSet ds = new DataSet();
    con.Open();
    string cmdtext = "select * from tb_Customer_Type where intID = '"+hf_UserID.Value+"'";
    //数据库记录保存到字符串
    //创建SqlDataAdapter数据适配器
    SqlDataAdapter sda = new SqlDataAdapter(cmdtext, con);
    //创建数据集
    //填充数据集合(如下:填充进字符串表名Master)
    sda.Fill(ds, "Master");
    GridView1.DataSource = ds;

    GridView1.DataBind();
    }

    #region 连接数据库

    private void ExcuteSql(String strSql)
    {


    //string strConn = "Data Source = .;initial Catalog = JLCallSystem;User ID = sa;Password=123456";
    string strConn = "Data Source = .;initial Catalog = JLCallSystem;User ID = sa;Password=123456";
    DbProviderFactory dbProviderFactory = DbProviderFactories.GetFactory("System.Data.SqlClient");
    DbConnection dbConn = dbProviderFactory.CreateConnection();
    dbConn.ConnectionString = strConn;
    dbConn.Open();
    DbCommand dbComm = dbProviderFactory.CreateCommand();
    dbComm.Connection = dbConn;
    dbComm.CommandText = strSql;
    dbComm.ExecuteNonQuery();
    dbConn.Close();
    dbConn.Dispose();


    }
    #endregion

    private void TestCon()
    {
    string strConn = "data source=.;initial catalog=JLCallSystem;user id=sa;password=123456";

    SqlConnection con = new SqlConnection(strConn);
    DataSet ds = new DataSet();
    con.Open();
    //自定义查询SQL字符串
    string type = this.txtstrType.Text; //需要查寻的数据,从TextBox中读取

    string cmdtext = "select * from tb_Customer_Type where strTypeValue like '%" + type + "%'";
    //string cmdtext = "select * from users where username like '%"+strTemp+"%'and phone1 like'%"+txtPhone.Text+"%'and phone2 like '%"+txtPhone.Text+"%'and phone3 like '%"+txtPhone.Text+"'and phone4 like'%"+txtPhone.Text+"%'and phone5 like '%"+txtPhone.Text +"%'";

    //数据库记录保存到字符串
    //创建SqlDataAdapter数据适配器
    SqlDataAdapter sda = new SqlDataAdapter(cmdtext, con);
    //创建数据集
    //填充数据集合(如下:填充进字符串表名Master)
    sda.Fill(ds, "Master");
    GridView1.DataSource = ds;
    GridView1.DataBind();
    }


    #region 数据绑定
    private void BindData()
    {
    string strConn = "data source=.;initial catalog=JLCallSystem;user id=sa;password=123456";

    SqlConnection con = new SqlConnection(strConn);
    DataSet ds = new DataSet();
    con.Open();
    //自定义查询SQL字符串
    string username = txtstrType.Text.Trim(); //需要查寻的数据,从TextBox中读
    string cmdtext = "select * from tb_Customer_Type";
    //数据库记录保存到字符串
    //创建SqlDataAdapter数据适配器
    SqlDataAdapter sda = new SqlDataAdapter(cmdtext, con);
    //创建数据集
    //填充数据集合(如下:填充进字符串表名Master)
    sda.Fill(ds, "Master");
    GridView1.DataSource = ds;
    GridView1.DataBind();

    }
    #endregion

    private void TestConAll()
    {
    string strConn = "data source=.;initial catalog=JLCallSystem;user id=sa;password=123456";

    SqlConnection con = new SqlConnection(strConn);
    DataSet ds = new DataSet();
    con.Open();
    string cmdtext = "select * from tb_Customer_Type where intID = '"+hf_UserID.Value+"' ";
    //数据库记录保存到字符串
    //创建SqlDataAdapter数据适配器
    SqlDataAdapter sda = new SqlDataAdapter(cmdtext, con);
    //创建数据集
    //填充数据集合(如下:填充进字符串表名Master)
    sda.Fill(ds, "Master");
    GridView1.DataSource = ds;
    GridView1.DataBind();
    }

  • 相关阅读:
    MS SQL执行大脚本文件时,提示“未能完成操作,存储空间不足,无法处理此命令”的解决办法
    一、Flux 是什么?
    for...in for..of
    循环总结
    javascript中几种this指向问题
    redux
    布局方式
    js获取前几个月的具体日期
    动态引入js文件
    获取页面url信息
  • 原文地址:https://www.cnblogs.com/HoverM/p/3796021.html
Copyright © 2011-2022 走看看