手机
当前位置:查字典教程网 >编程开发 >asp.net教程 >asp.net利用存储过程实现模糊查询示例分享
asp.net利用存储过程实现模糊查询示例分享
摘要:复制代码代码如下:USE[TestDB]GO/******Object:Table[dbo].[tblCustomer]ScriptDate...

复制代码 代码如下:

USE [TestDB]

GO

/****** Object: Table [dbo].[tblCustomer] Script Date: 01/18/2014 22:01:53 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[tblCustomer](

[id] [int] IDENTITY(1,1) NOT NULL,

[name] [nvarchar](100) NULL,

[dat] [date] NULL

) ON [PRIMARY]

GO模糊查询

复制代码 代码如下:

CREATE PROCEDURE SearchCustomer

-- Add the parameters for the stored procedure here

@name nvarchar(100)

AS

SELECT * FROM dbo.tblCustomer WHERE name LIKE '%'+@name+'%'

GO

复制代码 代码如下:

using (SqlConnection cn = new SqlConnection("Server=localhost;Database=TestDB;Trusted_Connection=True;"))

{

cn.Open();

string str = "关键字";

//str = null;

SqlCommand cmd = new SqlCommand("SearchCustomer", cn);

cmd.CommandType = CommandType.StoredProcedure;

DataTable dt = new DataTable();

SqlDataAdapter da = new SqlDataAdapter(cmd);

da.SelectCommand.Parameters.Add("@name", SqlDbType.NVarChar).Value = str;

da.Fill(dt);

Debug.Assert(dt.Rows.Count > 0);

GridView1.DataSource=dt;

GridView1.Bind();

cn.Close();

}

【asp.net利用存储过程实现模糊查询示例分享】相关文章:

asp.net SAF 中缓存服务的实现第1/5页

asp.net实现在线音乐播放器示例

asp.net中C++单例实现问题分析

ASP.NET中利用存储过程实现模糊查询

asp.net中利用Jquery+Ajax+Json实现无刷新分页的实例代码

asp.net操作xml增删改示例分享

asp.net 多字段模糊查询代码

用存储过程向数据库存值的具体实现

.net的socket异步通讯示例分享

asp.net用三层实现多条件检索示例

精品推荐
分类导航