亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

ASP.NET實(shí)現(xiàn)按拼音碼模糊查詢的方法

 更新時(shí)間:2022年05月05日 08:38:44   投稿:lijiao  
我們?cè)谧鰯?shù)據(jù)錄入或者查詢的時(shí)候,經(jīng)常需要實(shí)現(xiàn)按用戶輸入的拼音碼進(jìn)行數(shù)據(jù)的模糊查詢功能,本文為大家介紹ASP.NET如何實(shí)現(xiàn)按拼音碼模糊查詢,需要的朋友可以參考下

整個(gè)過程分為兩部分:生成拼音碼字段、按拼音碼進(jìn)行模糊查詢。

批量生成拼音碼字段的實(shí)現(xiàn):

protected void Button1_Click1(object sender, EventArgs e)
 {
 string strSQL;
 strSQL = "select mc from TEST001";
 IDataReader dr = dac.DataReaderQuery(strSQL);
 while (dr.Read())
 {
  string mc=dr["mc"].ToString();
  string pym = StrToPinyin.GetChineseSpell(mc);
  if (pym.Length > 6)
  {
  pym = pym.Substring(0, 6);//我這里只去了6位,大家可以看自己愛好而定!
  } 
  string updateSql = "update TEST001 set pym ='" + pym + "' where mc='" + mc + "'";

  dac.update(updateSql);
 }
 dr.Close(); 
 Response.Write("<script>alert('操作成功!');</script>");
 }

StrToPinyin 類的GetChineseSpell方法(取漢字拼音字母):

public static string GetChineseSpell(string strText)
 {
 if (strText == null || strText.Length == 0)
  return strText;
 System.Text.StringBuilder myStr = new System.Text.StringBuilder();
 foreach (char vChar in strText)
 {
  // 若不是漢字則直接輸出 
  if ((int)vChar < 19968 || (int)vChar > 40869)
  {
  myStr.Append(char.ToUpper(vChar));
  }
  else if ((int)vChar >= 19968 && (int)vChar <= 40869)
  {
  // 若字符Unicode編碼在編碼范圍則 查漢字列表進(jìn)行轉(zhuǎn)換輸出 
  foreach (string strList in strChineseCharList)
  {
   if (strList.IndexOf(vChar) > 0)
   {
   myStr.Append(strList[0]);
   break;
   }
  }
  }
 }
 return myStr.ToString();
 }

按拼音碼進(jìn)行模糊查詢:

這個(gè)簡(jiǎn)單了,用select查詢,where條件用LIKE即可,相信大家一定都會(huì)操作。

相信以后在實(shí)現(xiàn)按用戶輸入的拼音碼進(jìn)行數(shù)據(jù)的模糊查詢功能的時(shí)候,大家就可以運(yùn)用今天所學(xué)的ASP.NET實(shí)現(xiàn)按拼音碼模糊查詢了。

相關(guān)文章

最新評(píng)論