C #------Mobile phone Number attribution query (query data)

Source: Internet
Author: User

usingMySql.Data.MySqlClient;usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.IO;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespaceshoujihao{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); }        Private voidImports_click (Objectsender, EventArgs e) {            //File Open dialog boxOpenFileDialog dlg =NewOpenFileDialog (); //If the user does not select a file, it returns            if(DLG. ShowDialog ()! =System.Windows.Forms.DialogResult.OK) {return; }            //get user-selected files            stringFileName =dlg.            FileName; //Read the selected file            using(Stream fs =NewFileStream (filename,filemode.open))using(StreamReader reader =NewStreamReader (FS, Encoding.default)) {                 //start reading this file                stringLine ; //Skip the first lineline =Reader.                ReadLine (); //Create a database link                using(Mysqlconnection conn =mysqlhelper.createconnection ())//Transaction Rollback                using(Mysqltransaction tx =Conn. BeginTransaction ()) {Try                    {                         while(line = reader.) ReadLine ())! =NULL)                        {                            //If the last behavior is an empty string, jump out of the loop                            if(string. IsNullOrEmpty (line)) { Break; }                            //divide the line string by the number                            string[] lines = line. Split (','); //Remove the "" number from the string                            stringMobilenumber = lines[1]. Trim ('"'); stringMobilearea = lines[2]. Trim ('"'); stringMobiletype = lines[3]. Trim ('"'); //Insert Database//Mysqlhelper.executenonquery (conn, "INSERT into T_mobile (Mobilenumber,mobilearea,mobiletype) VALUES (@ Mobilenumber, @MobileArea, @MobileType)) ",//new Mysqlparameter {parametername = "@MobileNumber", Value = Mobilenumber},//new Mysqlparameter {parametername = ", @MobileArea", Value = Mobilearea},//new Mysqlparameter {parametername = "@MobileType", Value = Mobiletype});Mysqlhelper.executenonquery (Conn,"INSERT into T_mobile (mobilenumber,mobilearea,mobiletype) VALUES (@MobileNumber, @MobileArea, @MobileType)",                                Newmysqlparameter {parametername ="@MobileNumber", Value =Mobilenumber},Newmysqlparameter {parametername ="@MobileArea", Value =Mobilearea},Newmysqlparameter {parametername ="@MobileType", Value =Mobiletype});                    } tx.commit (); }                    Catch(Exception ex) {TX.                        Rollback (); MessageBox.Show ("Import Failed"+Ex.                    Message); }}} MessageBox.Show ("Import Successful!"); }        Private voidCx_click (Objectsender, EventArgs e) {            //get the phone number entered by the user            stringPhonenum =Textphonenum.text; //The first seven digits of the user's mobile phone number            stringPhonefix = phonenum.substring (0,7); //go to database query informationDataTable table = Mysqlhelper.executequery ("SELECT Mobilenumber,mobilearea from t_mobile WHERE mobilenumber = @phoneFix",                Newmysqlparameter {parametername ="@phoneFix", Value =Phonefix}); //            if(table. Rows.Count <=0) {MessageBox.Show ("Wood has query to data"); }            Else{DataRow row= table. rows[0]; stringMobilearea = (string) row[1]; stringMobiletype = (string) row[2]; MessageBox.Show (Mobilearea+Mobiletype); }        }    }}

C #------Mobile phone Number attribution query (query data)

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.