您现在的位置是:网站首页> 编程资料编程资料
asp.net利用存储过程实现模糊查询示例分享_实用技巧_
2023-05-24
313人已围观
简介 asp.net利用存储过程实现模糊查询示例分享_实用技巧_
复制代码 代码如下:
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();
}
您可能感兴趣的文章:
相关内容
- .NET操作Excel实例分享_实用技巧_
- aspx中的mysql操作类sqldatasource使用示例分享_实用技巧_
- .NET的file文件上传控件使用方法 修改web.config文件上传大文件_实用技巧_
- asp.net弹出窗口 返回值_实用技巧_
- Repeater事件OnItemCommand取得行内控件的方法_实用技巧_
- 利用sender的Parent获取GridView中的当前行(获取gridview的值)_实用技巧_
- asp.net2.0中css失效的解决方法_实用技巧_
- gridview自动排序示例分享_实用技巧_
- VS2005打开VS2008项目的2种方法(vs2005怎么打开2008)_实用技巧_
- asp.net解决上传4M文件限制_实用技巧_
