自學.net(4)上傳手機號碼歸屬地到資料庫

來源:互聯網
上載者:User

標籤:style   blog   color   os   io   ar   for   檔案   資料   

using Microsoft.Win32;using System;using System.Collections;using System.Collections.Generic;using System.Data.SqlClient;using System.IO;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Shapes;namespace wenjianduqu{    /// <summary>    /// haomaguishudi.xaml 的互動邏輯    /// </summary>    public partial class haomaguishudi : Window    {        public haomaguishudi()        {            InitializeComponent();        }        private void btnImport_Click(object sender,       RoutedEventArgs e)        {            OpenFileDialog ofg = new OpenFileDialog();            ofg.Filter = "文字檔|*.txt";            if (ofg.ShowDialog()==false)            {                return;            }
       //把txt檔案裡的資料放到lines的這個集合裡去 IEnumerable
<string> lines = File.ReadLines(ofg.FileName, Encoding.Default);
        //也可以用foreach,但是第一行的資料和後面的不一樣,還是用for方便點
for (int i = 1; i < lines.Count(); i++) {
          //效果等同於lines[i]
string line = lines.ElementAt(i);
          //以分隔字元的方式把資料分割開,存到數組裡
string[] stri = line.Split(‘\t‘); string haoDuan = stri[0]; string diQu = stri[1];
          //未經處理資料資訊帶“”需要用.Trim方法把雙引號去掉 diQu.Trim(
‘"‘); string leiXing = stri[2]; leiXing.Trim(‘"‘); string quHao = stri[3]; quHao.Trim(‘"‘);
          //字串前面加個@的話可以多行輸出,要不都擠到一行太難看 SqlHelper.ExecuteNonQuery(
@"insert into T_Tel (haoduan,diqu,leixing,quhao) values (@haoduan,@diqu,@leixing,@quhao)", new SqlParameter("@haoduan",haoDuan), new SqlParameter("@diqu", diQu), new SqlParameter("@leixing", leiXing), new SqlParameter("@quhao", quHao)); } MessageBox.Show("匯入成功"); } }}

新手,只能寫成這樣了,最佳化什麼的一點也不會,現在向上傳資料的速度好慢,得在研究看看能不能加個進度條什麼的

自學.net(4)上傳手機號碼歸屬地到資料庫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.