"ADO" 5, mobile phone attribution to query (Winfrom)

Source: Internet
Author: User

Using System.IO;

There is a TXT file for the database mobile number, the format is: 13500000000-13560000000-China Mobile

Search Result: Hunan Mobile [Shaoyang]
Folder selection dialog box FolderBrowserDialog;

String[] Directory.GetFiles (path, type, option)//Search for files in directory according to wildcard characters
Path.getfilenamewithoutextension (file name)//Get the file name (do not extend the name)
Path.Combine (path 1, path 2)//merge two paths
Path.getfilename (path)//Get file name (with suffix)
Path.GetFullPath (path)//Get the full path of the file

Purge old data before importing

The interface is like this:
A text input box: txtmessage
A query button: Btncha
An Import button: Btninput
A Label control: labmessage

Private voidBtninput_click (Objectsender, EventArgs e)//Import button click event{FolderBrowserDialog Dlg=NewFolderBrowserDialog ();//Select Directory dialog Box    if(DLG. ShowDialog ()! = DialogResult.OK)//Determine If the point is OK    {        return; }    stringPath = dlg. SelectedPath;//Get directory path    stringSTR = configurationmanager.connectionstrings["ConnStr"]. ConnectionString;//Get String    using(SqlConnection conn =NewSqlConnection (STR))//connecting using the variable str{Conn.        Open (); using(SqlCommand cmd =Conn. CreateCommand ()) {Cmd.commandtext="Delete from T_phone";//Delete Table Firstcmd.         ExecuteNonQuery (); }    }     //search all. txt files in the specified directory     string[] files = directory.getfiles (path,"*.txt", searchoption.alldirectories); using(SqlConnection conn =NewSqlConnection (STR)) {Conn.           Open (); using(SqlCommand cmd =Conn. CreateCommand ()) {Cmd.commandtext="INSERT INTO T_phone (starno,endno,name) VALUES (@SN, @EN, @NA)"; foreach(stringFileinchfiles) {             stringCarrier = path.getfilenamewithoutextension (file);//get file name, no extension             string[] lines = File.ReadAllLines (File, Encoding.default);//reads all rows, the default encoding is UTF-8                        foreach(stringLineinchlines) {                string[] str = line. Split ('-');//split by "-" character                stringStartn = str[0]; stringENDN = str[1]; stringName = str[2]; Cmd.          Parameters.clear (); //clear the Parameters first .Cmd. Parameters.Add (NewSqlParameter ("SN", Startn)); Cmd. Parameters.Add (NewSqlParameter ("EN", ENDN)); Cmd. Parameters.Add (NewSqlParameter ("NA", Carrier +Name)); Cmd.            ExecuteNonQuery (); }} MessageBox.Show ("Import Done! "); }        } } Private voidBtncha_click (Objectsender, EventArgs e)//Query button, click event {    stringSTR = configurationmanager.connectionstrings["ConnStr"].    ConnectionString; using(SqlConnection conn =NewSqlConnection (STR)) {Conn.       Open (); using(SqlCommand cmd =Conn. CreateCommand ()) {Cmd.commandtext="Select Name from T_phone where starno< @Num and endno> @Num"; Cmd. Parameters.Add (NewSqlParameter ("@Num", TxtNum.Text.Trim ())); SqlDataReader Dr=cmd.        ExecuteReader (); if(Dr. Read ()) {stringResult =convert.tostring (dr["Name"]); Labmessage.text=NULL; Labmessage.text="Number Address:"+result; }        Else{Labmessage.text="Number Address:"+"Address Unknown! "; }      }   } }

"ADO" 5, mobile phone attribution to query (Winfrom)

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.