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

  • 相关阅读:
    数据库之表与表之间的关系
    数据库之完整性约束条件
    基本数据类型
    数据库
    Django ajax 发送post请求 前端报错解决
    Django数据库建立注意事项
    编程单词汇总
    程序员必掌握600单词
    python思维导图
    用jQuery模拟hover选择效果
  • 原文地址:https://www.cnblogs.com/HoverM/p/3796021.html
Copyright © 2011-2022 走看看