Now another database has the goodname field, which is all Chinese names. Now we need to add a field named shorname, which is the first letter of each Chinese Character in the Chinese name. The conversion process calls easyfunclib. dll.
Using system; using system. collections. generic; using system. LINQ; using system. text; // This dll can be found online. // The main purpose is to convert Chinese to pinyin, for example, "People's Republic of China" to "zhrmghg" using easyfunclib; using system. data. sqlclient; using system. data; using system. data. oledb; namespace translate {class program {/// <summary> // modify the shortname column of the database and change the value to the abbreviation of goodname. /// </Summary> /// <Param name = "ARGs"> </param> static void main (string [] ARGs) {// connection string, provider = sqloledb string connectionstring = "Data Source = .; initial catalog = kuweichaxun; user id = sa; Pwd = sa; provider = sqloledb "; using (oledbconnection conn = new oledbconnection (connectionstring) {// query string, which must contain the primary key, otherwise, the update statement string sqlstring = "select [row], [FLOOR], [Line], [bit], [goodname], [shortname] from [storeinfo]"; dataset DS = new dataset (); try {Conn. open (); oledbdataadapter adapter = new oledbdataadapter (); adapter. selectcommand = new oledbcommand (sqlstring, Conn); oledbcommandbuilder builder = new oledbcommandbuilder (adapter); adapter. fill (DS); foreach (datatable table in DS. tables) {foreach (datarow DR in table. rows) {string older = Dr [4]. tostring (); // convert goodname to shortname Dr [5] = chinese2pinyin. getfirstpinyin (older); console. writeline (Dr [5]) ;}// update to the database adapter. update (DS);} catch (system. data. sqlclient. sqlexception e) {Conn. close (); throw new exception (E. message );}}}}}