Dbdataadapter. Update Method

Source: Internet
Author: User
 

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 );}}}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.