关于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 ...
随机推荐
- 第一发。。。codeforces 609 C Load Balancing 贪心
/*题意:给你一个序列经过最小变换,变换一次为一个数+1,一个数-1,使得最大值与最小值相差1:思路:与最后得到的序列相差的sum/2:*/#include<iostream> #incl ...
- 模仿$.Callbacks实现
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Quartz.Net 调度框架配置介绍
在平时的工作中,估计大多数都做过轮询调度的任务,比如定时轮询数据库同步,定时邮件通知等等.大家通过windows计划任务,windows服务等都实现过此类任务,甚至实现过自己的配置定制化的框架.那今天 ...
- phpcms标签大全V9
转自:http://blog.csdn.net/cloudday/article/details/7343448调用头部 尾部 {template "content"," ...
- html中出现的script失效
如果在Controller中出现script代码类似 $hello_str='Hello God<script>alert(3);</script>'; 那么我不希望在传给vi ...
- iOS - Delegate 代理
1.Delegate 1.1 协议 协议:是多个类共享的一个方法列表.协议中列出的方法没有相应的实现,计划由其他人来实现.协议中列出的方法,有些是可以选择实现,有些是必须实现. 1>.如果你定义 ...
- iOS - Plist 数据解析
前言 NS_AVAILABLE(10_6, 4_0) @interface NSPropertyListSerialization : NSObject 如果对象是 NSArray 或 NSDicti ...
- JS获取用户控件中的子控件Id
用户控件 <asp:HiddenField ID="hfGradeId" runat="server" /> <asp:HiddenField ...
- Sqlerver_各类函数
SQL Aggregate 函数 SQL Aggregate 函数计算从列中取得的值,返回一个单一的值. 有用的 Aggregate 函数: AVG() - 返回平均值-SELECT AVG(colu ...
- HBase的shell命令行界面按退格键(Backspace)无法删除问题
在HBase的shell命令行界面输入错误项按"退格键"删除,却怎么也删除不了: 解决办法: 第一步,修改SecureCRT的设置参数: 第二步,按"Ctrl+退格键(B ...