整個(gè)過(guò)程分為兩部分:生成拼音碼字段、按拼音碼進(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位,大家可以看自己愛(ài)好而定! } 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) { // 若不是漢字則直接
按拼音碼進(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)按拼音碼模糊查詢了。
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com