富贵资源网 Design By www.hznty.com

复制代码 代码如下:
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();
}

富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com