Home > Net >  CSV or plain text import sqlite in c #
CSV or plain text import sqlite in c #

Time:10-13

CSV or plain text import sqlite how to write code in c #, for the great god reply

CodePudding user response:

Refer to the two namespace
using System.Collections.Generic;
Using System. The Data;


Installation: AccessDatabaseEngine this plugin


The code below
The static void Main (string [] args)
{
String filePath=@ "you put the file path";
String strCon="Provider=Microsoft. ACE. The OLEDB. 12.0; Data Source="+ filePath +"; Extended Properties='Excel Xml 12.0; HDR=YES; IMEX=1 '";
System. Data. The OleDb. OleDbConnection myConn=new System. The Data. The OleDb. OleDbConnection (strCon);
MyConn. The Open ();
The DataTable schemaTable=myConn. GetOleDbSchemaTable (System) Data. The OleDb. OleDbSchemaGuid. Tables, null);
String tableName=schemaTable. Rows [0] [2]. The ToString (). The Trim ();//tag name
String strCom="Select * from [Sheet1 $]".//query
System. Data. The OleDb. OleDbDataAdapter myCommand=new System. The Data. The OleDb. OleDbDataAdapter (strCom myConn);
//create a DataSet object
The DataSet myDataSet=new DataSet ();
//get yourself a DataSet object
MyCommand. The Fill (myDataSet);
//close this data link
MyConn. Close ();
The DataTable dtTask=myDataSet. Tables [0];

List List=new List (a);
For (int k=0; k {
The userInfo model=new the userInfo ();
Model. The id=the Convert. ToInt32 (dtTask Rows [k] [r]. "number" ToString ());
Model. The name=dtTask. Rows [k] [r]. "name" ToString ();
Model. The identity=dtTask. Rows [k] [r]. "id card" the ToString ();
List. The Add (model);
}
}


Public class the userInfo
{
///& lt; Summary>
///no.
///& lt;/summary>
Public int id {get; The set; }
///& lt; Summary>
///name
///& lt;/summary>
Public string name {get; The set; }
///& lt; Summary>
///id
///& lt;/summary>
Public string identity {get; The set; }
}
  • Related