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编码在编码范围则 查汉字列表进行转换输出
foreach (string strList in strChineseCharList)
{
if (strList.IndexOf(vChar) > 0)
{
myStr.Append(strList[0]);
break;
}
}
}
}
return myStr.ToString();
}