Small Data volume CSV file Data import Database (IDEA)

Source: Internet
Author: User
Tags import database

Write a general idea, because SQL Server provides a graphical interface that can be imported directly.

1, private static string GetConnectionString (String folderpath)//folder path

{

string [email protected] "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" [email protected] "\; Extended properties= ' Text; ';

return connectionString;

}

2, String sql= "select from 1.csv";

DataTable dt=oledbhelper.query (@ "C:\Users\Administrator\Desktop", SQL);

StringBuilder sb=new StringBuilder ();

String portcode=string. Empty;

String namecode=string. Empty;

if (Dt!=null&&dt. ROWS.COUNT>0)

{

foreach (DataRow dr in Dt. Rows)

{

portcode=dr["Portcode"]. ToString ();

namecode=dr["Namecode"]. ToString ();

Sb. Appendline ("INSERT into TableName (Portcode,namecode) VALUES ('" +portcode+ "', '" +namecode+ "')");

}

String RESULT=SB. ToString ();

}

Dbhelper.executesql (result);

  

Small Data volume CSV file Data import Database (IDEA)

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.