2011-10-19 4 views
1

SQL 데이터베이스에 저장 프로 시저에 유니 코드 문자열 (예 : "ش")을 보내려고합니다.유니 코드 문자열을 C#에서 SQL Server 2008 DB로 보내기

SqlConnection connection = new SqlConnection("Data Source=(local);Initial Catalog=Khane;Integrated Security=True"); 

SqlCommand command = new SqlCommand(); 
command.Connection = connection; 
command.CommandType = CommandType.Text; 



command.CommandText = s; 
connection.Open(); 



SqlDataReader reader = command.ExecuteReader(); 

while (reader.Read()) 
{ 
Common.CommonPersonSerchResult res = new Common.CommonPersonSerchResult(); 

res.ID = (int)reader.GetValue(0); 
res.FirstName = reader.GetValue(1).ToString(); 
res.LastName = reader.GetValue(2).ToString(); 
res.FatherName = reader.GetValue(3).ToString(); 
res.NationalCode = (int)reader.GetValue(4); 
res.ShenasnameCode = (int)reader.GetValue(5); 
res.BirthDate = reader.GetValue(6).ToString(); 
res.State = reader.GetValue(7).ToString(); 
res.City = reader.GetValue(8).ToString(); 
res.PostalCode = (int)reader.GetValue(10); 
res.SportType = reader.GetValue(11).ToString(); 
res.SportStyle = reader.GetValue(12).ToString(); 
res.RegisterType = reader.GetValue(13).ToString(); 
res.Ghahremani = reader.GetValue(14).ToString(); 

SerchResult.Add(res); 

} 

connection.Close(); 

그러나 나는 어떤 결과를 볼 수 있지만 일부 행이 내 저장 프로 시저입니다

를 표시 할 수 있습니다 알고 : 내 코드는

USE [Khane] 
GO 
/****** Object: StoredProcedure [dbo].[QuickSerch] Script Date: 10/19/2011 18:31:22 ******/ 
SET ANSI_NULLS ON 
GO 
SET QUOTED_IDENTIFIER ON 
GO 
-- ============================================= 
-- Author:  <Author,,Name> 
-- Create date: <Create Date,,> 
-- Description: <Description,,> 
-- ============================================= 
ALTER PROCEDURE [dbo].[QuickSerch] 
@item nvarchar(300) 
AS 
BEGIN  
select * from PersonsDataTbl 
where 
Name like '%@item%' or 
LastName like '%@item%' or 
FatherName like '%@item%' or 
NationalCode like '%@item%' or 
ShenasnameCode like '%@item%' or 
BirthDate like '%@item%' or 
State like '%@item%' or 
City like '%@item%' or 
Address like '%@item%' or 
PostalCode like '%@item%' or 
SportType like '%@item%' or 
SportStyle like '%@item%' or 
RegisterType like '%@item%' or 
Ghahremani like '%@item%' 
END 

답변

4

귀하의 저장 프로 시저 코드는 다음과 같아야합니다.

LIKE '%' + @item + '%' 

그렇지 않으면 다음을 포함하는 값을 찾고 있습니다. 리터럴 캐릭터 라인 "@item".

또한 테이블에 행 수가 많으면 코드의 실적이 좋지 않을 수 있습니다. OR 문과 주요 와일드 카드 사이에서 모든 인덱스를 사용할 수 없습니다. 전체 텍스트 검색을 살펴볼 수 있습니다.

+0

+1 그리고 데이터 정렬 및 강조는 조사해야 할 수도 있습니다. 나는 DB에 많은 행이 없다는 것을 진심으로 바라고 ... 테이블 스캔 도시. – StuartLC

+0

감사하지만 전 텍스트 검색을 알지 못하며이 프로젝트는 필요하지 않습니다. 고맙습니다 agin.LIKE '%'+ @item + '%'worked –

관련 문제