Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
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.Navigation;
Using System.Windows.Shapes;
Using System.IO;
Using Microsoft.Win32;
Using System.Data.SqlClient;
Namespace mobile phone number attribution to search
{
<summary>
The interactive logic of MainWindow.xaml
</summary>
public partial class Mainwindow:window
{
Public MainWindow ()
{
InitializeComponent ();
}
private void Button_Click (object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog ();
Ofd. filter= "text file |*.txt";
if (OFD. ShowDialog ()!=true)
{
Return
}
//ienumerable<string> lines = File.readlines (ofd. FileName, Encoding.default);
String[] lines = File.readlines (ofd. FileName, Encoding.default). ToArray ();
for (int i = 1; i < lines. Count (); i++)
{
String line =lines[i];
String[] segs= line. Split (' \ t ');//Note how file text is split
String Starttelnum=segs[0];
String city = Segs[1];
City = city. Trim (' "');
String teltye= segs[2];
Teltye = Teltye. Trim (' "');
Sqlhelper.excutenonquery ("INSERT into T_tel (Startnum, Telarea,teltype) VALUES ('" + Starttelnum + "', '" + City + "', '" + Teltye + "')");
//sqlhelper.excutenonquery ("INSERT into T_tel (Startnum, Telarea,teltype) VALUES (@startnum, @telarea, @teltype)",
//New SqlParameter ("@startnum", Starttelnum),
//New SqlParameter ("@telarea", city),
//New SqlParameter ("@teltype", Teltye));
}
MessageBox.Show ("Import succeeded! ");
}
}
}
This method is inefficient, takes a long time, only for learning!
C # text File Import Database