2011-10-19 11 views
1

SQLデータベースのストアドプロシージャにいくつかのユニコード文字列(「ش」など)を送信したいとします。 と私のコードは次のとおりです。Unicode文字列を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 + '%' –

関連する問題