Self-study. NET (4) Upload mobile number attribution to database

Source: Internet
Author: User

usingMicrosoft.Win32;usingSystem;usingSystem.Collections;usingSystem.Collections.Generic;usingSystem.Data.SqlClient;usingSystem.IO;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows;usingSystem.Windows.Controls;usingSystem.Windows.Data;usingSystem.Windows.Documents;usingSystem.Windows.Input;usingSystem.Windows.Media;usingSystem.Windows.Media.Imaging;usingSystem.Windows.Shapes;namespacewenjianduqu{/// <summary>    ///the interactive logic of Haomaguishudi.xaml/// </summary>     Public Partial classHaomaguishudi:window { PublicHaomaguishudi () {InitializeComponent (); }        Private voidBtnimport_click (Objectsender, RoutedEventArgs e) {OpenFileDialog Ofg=NewOpenFileDialog (); Ofg. Filter="text Files |*.txt"; if(Ofg. ShowDialog () = =false)            {                return; }
Put the data in the TXT file into this collection of lines IEnumerable
<string> lines =File.readlines (Ofg. FileName, Encoding.default);
You can also use foreach, but the first row of data is not the same as the one behind it, or for a convenient point
for(inti =1; I < lines. Count (); i++) {
Effect equivalent to Lines[i]
stringline =lines. ElementAt (i);
Split the data in a delimiter and save it in an array
string[] Stri = line. Split ('\ t'); stringHaoduan = stri[0]; stringDiqu = stri[1];
Raw data information with "" needs to be used. Trim method to remove the double quotes Diqu.trim (
'"'); stringleixing = stri[2]; Leixing.trim ('"'); stringQuhao = stri[3]; Quhao.trim ('"');
If the string is preceded by a @ words can be multiple lines of output, or all squeezed into a row too ugly sqlhelper.executenonquery (
@"INSERT INTO T_tel (Haoduan,diqu,leixing,quhao) VALUES (@haoduan, @diqu, @leixing, @quhao)", NewSqlParameter ("@haoduan", Haoduan),NewSqlParameter ("@diqu", Diqu),NewSqlParameter ("@leixing", leixing),NewSqlParameter ("@quhao", Quhao)); } MessageBox.Show ("Import succeeded"); } }}

Novice, can only be written like this, optimize what is not a bit, now to upload data speed is very slow, you have to study to see if you can add a progress bar or something

Self-study. NET (4) Upload mobile number attribution to database

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.