Copy codeThe Code is as follows:
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 fuzzy search
Copy codeThe Code is as follows:
Create procedure SearchCustomer
-- Add the parameters for the stored procedure here
@ Name nvarchar (100)
AS
SELECT * FROM dbo. tblCustomer WHERE name LIKE '%' + @ name + '%'
GO
Copy codeThe Code is as follows:
Using (SqlConnection cn = new SqlConnection ("Server = localhost; Database = TestDB; Trusted_Connection = True ;"))
{
Cn. Open ();
String str = "keyword ";
// 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 ();
}