关于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();
}
关于gridview 实现查询功能的方法的更多相关文章
- asp.net 中使用 pagedlist 分页并具有查询功能的实现方法
用pagedlist在项目中做分页已N次了,今天再次用实例来实现一个带查询功能的分页例子. 1.在view代码: @using PagedList.Mvc@model BGZS.Models.User ...
- C#3.0新增功能09 LINQ 基础07 LINQ 中的查询语法和方法语法
连载目录 [已更新最新开发文章,点击查看详细] 介绍性的语言集成查询 (LINQ) 文档中的大多数查询是使用 LINQ 声明性查询语法编写的.但是在编译代码时,查询语法必须转换为针对 .NET ...
- 创建ASP.NET Core MVC应用程序(5)-添加查询功能 & 新字段
创建ASP.NET Core MVC应用程序(5)-添加查询功能 & 新字段 添加查询功能 本文将实现通过Name查询用户信息. 首先更新GetAll方法以启用查询: public async ...
- sqlserver 多库查询 sp_addlinkedserver使用方法(添加链接服务器)
sqlserver 多库查询 sp_addlinkedserver使用方法(添加链接服务器) 我们日常使用SQL Server数据库时,经常遇到需要在实例Instance01中跨实例访问Instanc ...
- ASP.NET MVC系列:为视图添加查询功能
首先,在MoviesController里添加一个查询方法,代码如下 public ActionResult SearchIndex(string title) { //查询数据库中的电影表 var ...
- 完善ext.grid.panel中的查询功能(紧接上一篇)
今天的代码主要是实现,Ext.grid.panel中的查询,其实我也是一名extjs新手,开始想的实现方式是另外再创建一个新的grid类来存放查询出的数据(就是有几个分类查询就创建几个grid类),这 ...
- ASP.NET MVC 学习4、Controller中添加SearchIndex页面,实现简单的查询功能
参考:http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/examining-the-edit-method ...
- JAVAEE——BOS物流项目09:业务受理需求分析、创建表、实现自动分单、数据表格编辑功能使用方法和工作单快速录入
1 学习计划 1.业务受理需求分析 n 业务通知单 n 工单 n 工作单 2.创建业务受理环节的数据表 n 业务通知单 n 工单 n 工作单 3.实现业务受理自动分单 n 在CRM服务端扩展方法根据手 ...
- 学习ASP.NET Core Razor 编程系列九——增加查询功能
学习ASP.NET Core Razor 编程系列目录 学习ASP.NET Core Razor 编程系列一 学习ASP.NET Core Razor 编程系列二——添加一个实体 学习ASP.NET ...
随机推荐
- [HDOJ3709]Balanced Number(数位dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3709 题意:求区间[L,R]内每一个数中是否存在一位,使得左边的各位数*距离=右边的各位数*距离(自己 ...
- 自定义类型转换器converter
作用:目前将日期转换成string,将string转换成我想要的类型 0509课件里讲 一.数据类型转换在web应用程序中,数据存在两个方向上的转换:1.当提交表单时 表单数据以字符串的形式提交 ...
- Native SQL
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- linux配置IP地址
1. ifconfig命令临时配置IP地址 ifconfig命令:查看与配置网络状态命令 如: ifconfig eht0 192.168.0.200 netmask 255.255.255.0 # ...
- Struts BaseAction工具类,封装Session,Request,Application,ModelDriven
package com.ssh.shop.action; import java.io.InputStream; import java.lang.reflect.ParameterizedType; ...
- hdu 3018 Ant Trip 欧拉回路+并查集
Ant Trip Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem ...
- hdu 3535 AreYouBusy 分组背包
AreYouBusy Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Probl ...
- nyoj 1058部分和问题(DFS)
部分和问题 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 给定整数a1.a2........an,判断是否可以从中选出若干数,使它们的和恰好为K. 输入 首先, ...
- Nofollow
今天整理一下SEO中经常用到的nofollow属性. nofollow它是HTML标签中的一个属性值,作用是告诉搜索引擎不要跟踪带有改属性值的链接, 用于指示搜索引擎不要追踪(即抓取)网页上的带有no ...
- (四)主控板改IP,升级app,boot,mac
给主控板升级boot要在boot界面进行,进入boot后,要先查看boot下ip和掩码是否和电脑ip(severip)在一个网段,不在的话要使用setenv命令设置ip地址和掩码.之后再输入upboo ...