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

关于gridview 实现查询功能的方法的更多相关文章

  1. asp.net 中使用 pagedlist 分页并具有查询功能的实现方法

    用pagedlist在项目中做分页已N次了,今天再次用实例来实现一个带查询功能的分页例子. 1.在view代码: @using PagedList.Mvc@model BGZS.Models.User ...

  2. C#3.0新增功能09 LINQ 基础07 LINQ 中的查询语法和方法语法

    连载目录    [已更新最新开发文章,点击查看详细] 介绍性的语言集成查询 (LINQ) 文档中的大多数查询是使用 LINQ 声明性查询语法编写的.但是在编译代码时,查询语法必须转换为针对 .NET ...

  3. 创建ASP.NET Core MVC应用程序(5)-添加查询功能 & 新字段

    创建ASP.NET Core MVC应用程序(5)-添加查询功能 & 新字段 添加查询功能 本文将实现通过Name查询用户信息. 首先更新GetAll方法以启用查询: public async ...

  4. sqlserver 多库查询 sp_addlinkedserver使用方法(添加链接服务器)

    sqlserver 多库查询 sp_addlinkedserver使用方法(添加链接服务器) 我们日常使用SQL Server数据库时,经常遇到需要在实例Instance01中跨实例访问Instanc ...

  5. ASP.NET MVC系列:为视图添加查询功能

    首先,在MoviesController里添加一个查询方法,代码如下 public ActionResult SearchIndex(string title) { //查询数据库中的电影表 var ...

  6. 完善ext.grid.panel中的查询功能(紧接上一篇)

    今天的代码主要是实现,Ext.grid.panel中的查询,其实我也是一名extjs新手,开始想的实现方式是另外再创建一个新的grid类来存放查询出的数据(就是有几个分类查询就创建几个grid类),这 ...

  7. ASP.NET MVC 学习4、Controller中添加SearchIndex页面,实现简单的查询功能

    参考:http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/examining-the-edit-method ...

  8. JAVAEE——BOS物流项目09:业务受理需求分析、创建表、实现自动分单、数据表格编辑功能使用方法和工作单快速录入

    1 学习计划 1.业务受理需求分析 n 业务通知单 n 工单 n 工作单 2.创建业务受理环节的数据表 n 业务通知单 n 工单 n 工作单 3.实现业务受理自动分单 n 在CRM服务端扩展方法根据手 ...

  9. 学习ASP.NET Core Razor 编程系列九——增加查询功能

    学习ASP.NET Core Razor 编程系列目录 学习ASP.NET Core Razor 编程系列一 学习ASP.NET Core Razor 编程系列二——添加一个实体 学习ASP.NET ...

随机推荐

  1. struts2 if标签示例

    下面总结一下struts2 中if标签的使用 (1)判断字符串是否为空 <s:if test="user.username==null or user.username==''&quo ...

  2. hibernate对象关系实现(二)一对一

    双向一对一以部门和经理为例: a.部门和经理类中各自由对方的引用:(省略了get/set方法) b.数据库两种方式实现:一种(b.1)是外键映射,并将外键添加唯一约束(至于哪个对象的主键做外键,可随意 ...

  3. python操作postgresql数据库

    import psycopg2 conn = psycopg2.connect(database=") cur = conn.cursor() cur.execute("CREAT ...

  4. 26个Jquery使用小技巧

    下面列出了一些Jquery使用技巧.比如有禁止右键点击.隐藏搜索文本框文字.在新窗口中打开链接.检测浏览器.预加载图片.页面样式切换.所有列等高.动态控制页面字体大小.获得鼠标指针的X值Y值.验证元素 ...

  5. gcc常用指令及相关知识

    1,gcc与g++的问题: 1.后缀为.c的,gcc把它当作是C程序,而g++当作是c++程序:后缀为.cpp的,两者都会认为是c++程序. 2.编译阶段,g++会调用gcc,对于c++代码,两者是等 ...

  6. (三)ubuntu学习前传—uboot常见环境变量

    1.环境变量如何参与程序运行(1)环境变量有2份,一份在Flash中,另一份在DDR中.uboot开机时一次性从Flash中读取全部环境变量到DDR中作为环境变量的初始化值,然后使用过程中都是用DDR ...

  7. JS作用域和预编译(转载 学习中。。。)

    JS在页面加载过程中顺序执行.但是分块预编译.执行. JS在执行前会进行类似”预编译”的操作,而且先预声明变量再预定义函数. 此时注意,是声明,不是定义,如:var a = 1; 在预编译中,只是执行 ...

  8. 转:strcpy实现的考察要点

    strcpy函数的实现 已知strcpy函数的原型是: char *strcpy(char *dst, const char *src); 实现strcpy函数 解释为什么要返回char * 假如考虑 ...

  9. foreach 相关

    20 Nov 08 深入理解PHP原理之foreach 作者: Laruence(   ) 本文地址: http://www.laruence.com/2008/11/20/630.html 转载请注 ...

  10. php数据通信方式

    一:curl$ch = curl_init();curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);curl_setopt($ch,CURLOPT_TIMEOU ...