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

  • 相关阅读:
    elementUI的table分页多选,记住上一页并勾选中,:row-key的使用方法
    如何在vue中使用svg
    父子组件传值,子组件接收不到值,并且无法动态更改video的视频源进行视频播放
    vue项目中如何使用dataform向后台传值
    'eslint'不是内部或外部命令,也不是可运行的程序
    小程序点击分享open-type="share"触发父元素怎么解决?
    vue项目启动报错Module build failed: Error: No PostCSS Config found in:
    eslint在webstorm中有错误警告
    微信小程序 image图片组件实现宽度固定 高度自适应
    JAVA设计模式学习--代理模式
  • 原文地址:https://www.cnblogs.com/HoverM/p/3796021.html
Copyright © 2011-2022 走看看