USE [TestDB]
GO/****** Object: Table [dbo].[tblCustomer] Script Date: 01/18/2014 22:01:53 ******/
SET ANSI_NULLS ON
GOSET QUOTED_IDENTIFIER ON
GOCREATE 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利用存储过程实现模糊查询示例分享请关注haodaima.com其它相关文章!