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();
    }

  • 相关阅读:
    SpringCloud2.0 Eureka Client 服务注册 基础教程(三)
    美国会计准则 Generally Accepted Accounting Principles (GAAP) 与 中国会计准则
    JavaScript的订阅者模式--实现一个简单的事件监听框架
    设计模式在外卖营销业务中的实践
    20行代码做一个简易微信群发工具需要哪些单词
    南怀瑾老师:一阴一阳之谓道,是个什么道?
    怎么追女生?
    正态分布(Normal distribution)也称“常态分布”,又名高斯分布
    广义线性模型
    逻辑回归表达式
  • 原文地址:https://www.cnblogs.com/HoverM/p/3796021.html
Copyright © 2011-2022 走看看