C # text File Import Database

Source: Internet
Author: User
Tags import database

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

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.