我想在TextBox中输入拼音,然后从数据库中检索数据。
例如:
    输入:zjmz
    显示:专家门诊(zhuan jia men zhen )
    如果数据库中没有“专家门诊”这个数据项,则不显示任何内容。  
    如果有多个,比如还有:“转嫁们真”( zhuan jia men zhen )
                           "作家们在“ ( zuo jia men zai )
    则显示多个,并让用户选择某个数据项。
 有点类似拼音输入法(简拼)
我见过公安系统的人员检索系统用的就是这中检索方法。那位大侠有这方面的代码,控件,资料
请赐教!急需!!! 谢谢!
100分不够,可以给300分。

解决方案 »

  1.   

    public string hz2py(string hz)  //获得汉字的区位码
            {
                byte[] sarr = System.Text.Encoding.Default.GetBytes(hz);
                int len = sarr.Length;
                if (len>1)
                {
                    byte[] array = new byte[2];
                    array = System.Text.Encoding.Default.GetBytes(hz);                int i1 = (short)(array[0] - '\0');
                    int i2 = (short)(array[1] - '\0');                //unicode解码方式下的汉字码
                    //            array = System.Text.Encoding.Unicode.GetBytes(hz);
                    //            int i1 = (short)(array[0] - '\0');
                    //            int i2 = (short)(array[1] - '\0');
                    //            int t1 = Convert.ToInt32(i1,16);
                    //            int t2 = Convert.ToInt32(i2,16);                int tmp=i1*256+i2;
                    string getpychar="*";//找不到拼音码的用*补位                     if(tmp>=45217&&tmp<=45252){getpychar= "A";}
                    else if(tmp>=45253&&tmp<=45760){getpychar= "B";}
                    else if(tmp>=47761&&tmp<=46317){getpychar= "C";}
                    else if(tmp>=46318&&tmp<=46825){getpychar= "D";}
                    else if(tmp>=46826&&tmp<=47009){getpychar= "E";}
                    else if(tmp>=47010&&tmp<=47296){getpychar= "F";}
                    else if(tmp>=47297&&tmp<=47613){getpychar= "G";}
                    else if(tmp>=47614&&tmp<=48118){getpychar= "H";}
                    else if(tmp>=48119&&tmp<=49061){getpychar= "J";}
                    else if(tmp>=49062&&tmp<=49323){getpychar= "K";}
                    else if(tmp>=49324&&tmp<=49895){getpychar= "L";}
                    else if(tmp>=49896&&tmp<=50370){getpychar= "M";}
                    else if(tmp>=50371&&tmp<=50613){getpychar= "N";}
                    else if(tmp>=50614&&tmp<=50621){getpychar= "O";}
                    else if(tmp>=50622&&tmp<=50905){getpychar= "P";}
                    else if(tmp>=50906&&tmp<=51386){getpychar= "Q";}
                    else if(tmp>=51387&&tmp<=51445){getpychar= "R";}
                    else if(tmp>=51446&&tmp<=52217){getpychar= "S";}
                    else if(tmp>=52218&&tmp<=52697){getpychar= "T";}
                    else if(tmp>=52698&&tmp<=52979){getpychar= "W";}
                    else if(tmp>=52980&&tmp<=53640){getpychar= "X";}
                    else if(tmp>=53689&&tmp<=54480){getpychar= "Y";}
                    else if(tmp>=54481&&tmp<=55289){getpychar= "Z";}
                    return getpychar;
                }
                else
                {
                    return hz;
                }
            }        public string transpy(string strhz)  //把汉字字符串转换成拼音码
            {
                string strtemp="";
                int strlen=strhz.Length;
                for (int i=0;i<=strlen-1;i++)
                {
                    strtemp+=hz2py(strhz.Substring(i,1));
                }
                return strtemp;
            }
      

  2.   

    我这里有个关于拼音的用户自定义函数
    create function f_GetPy(@str nvarchar(4000))
    returns nvarchar(4000)
    as
    begin
    declare @strlen int,@re nvarchar(4000)
    declare @t table(chr nchar(1) collate Chinese_PRC_CI_AS,letter nchar(1))
    insert into @t(chr,letter)
      select '吖','A' union all select '八','B' union all
      select '嚓','C' union all select '咑','D' union all
      select '妸','E' union all select '发','F' union all
      select '旮','G' union all select '铪','H' union all
      select '丌','J' union all select '咔','K' union all
      select '垃','L' union all select '嘸','M' union all
      select '拏','N' union all select '噢','O' union all
      select '妑','P' union all select '七','Q' union all
      select '呥','R' union all select '仨','S' union all
      select '他','T' union all select '屲','W' union all
      select '夕','X' union all select '丫','Y' union all
      select '帀','Z'
      select @strlen=len(@str),@re=''
      while @strlen>0
      begin
        select top 1 @re=letter+@re,@strlen=@strlen-1
          from @t a where chr<=substring(@str,@strlen,1)
          order by chr desc
        if @@rowcount=0
          select @re=substring(@str,@strlen,1)+@re,@strlen=@strlen-1
      end
      return(@re)
    end
    比如说:要从雇员表中查找叫李明的记录
    SELECT *
    FROM Employee
    WHERE (dbo.f_GetPy(Name) = 'lm')
      

  3.   

    --可以直接写SQL函数,比如zt一个邹建的--sql2000 查询分析器中运行如下脚本/*--获得汉字字符串的首字母   根据大力的贴子改成.将大力的两个函数合并成了一个函数.
       可以应用于助记码的查询
    --*/
    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[fGetPy]') and xtype in (N'FN', N'IF', N'TF'))
    drop function [dbo].[fGetPy]
    GO--创建取拼音函数
    create function fGetPy(@Str varchar(500)='')
    returns varchar(500)
    as
    begin
    declare @strlen int,@return varchar(500),@ii int
    declare @n int,@c char(1),@chn nchar(1) select @strlen=len(@str),@return='',@ii=0
    set @ii=0
    while @ii<@strlen
    begin
    select @ii=@ii+1,@n=63,@chn=substring(@str,@ii,1)
    if @chn>'z'
    select @n = @n +1
    ,@c = case chn when @chn then char(@n) else @c end
    from(
    select top 27 * from (
    select chn = '吖'
    union all select '八'
    union all select '嚓'
    union all select '咑'
    union all select '妸'
    union all select '发'
    union all select '旮'
    union all select '铪'
    union all select '丌' --because have no 'i'
    union all select '丌'
    union all select '咔'
    union all select '垃'
    union all select '嘸'
    union all select '拏'
    union all select '噢'
    union all select '妑'
    union all select '七'
    union all select '呥'
    union all select '仨'
    union all select '他'
    union all select '屲' --no 'u'
    union all select '屲' --no 'v'
    union all select '屲'
    union all select '夕'
    union all select '丫'
    union all select '帀'
    union all select @chn) as a
    order by chn COLLATE Chinese_PRC_CI_AS 
    ) as b
    else set @c='a'
    set @return=@return+@c
    end
    return(@return)
    endgo
    --测试
    select * from
    --此处替换为你的表名和字段名
    (select '专家门诊' as 字段名 union 
     select '转嫁们真' union
             select  '作家们在' union
     select '近身剪' union
     select 'jinjazz') a
    where dbo.fgetpy(字段名)='zjmz'--删除拼音函数
    drop function fgetpy
      

  4.   

    http://iheshi.cnblogs.com/archive/2005/10/07/249782.html