CSV files, commonly known as "comma-separated files". You can use iostream to read CSV files in a specified format...
I thought it was just this way, huh, huh, until one day, I saw the text connection on www.connectionstrings.com.
String:
Text
-
- ODBC
- Standard:
"Driver = {Microsoft text Driver (*. txt; *. CSV)}; DBQ = c: \ txtfilesfolder \; extensions = ASC, CSV, tab, txt ;"
- OLE DB
- Standard:
"Provider = Microsoft. Jet. oledb.4.0; Data Source = c: \ txtfilesfolder \; extended properties =" "text; HDR = yes; FMt = delimited """
"HDR = yes;" indicates that the first row contains columnnames, not data
- Standard:
"Driver = {Microsoft text Driver (*. txt; *. CSV)}; DBQ = c: \ txtfilesfolder \; extensions = ASC, CSV, tab, txt ;"
- OLE DB
- Standard:
"Provider = Microsoft. Jet. oledb.4.0; Data Source = c: \ txtfilesfolder \; extended properties =" "text; HDR = yes; FMt = delimited """
"HDR = yes;" indicates that the first row contains columnnames, not data
- Standard:
"Provider = Microsoft. Jet. oledb.4.0; Data Source = c: \ txtfilesfolder \; extended properties =" "text; HDR = yes; FMt = delimited """
"HDR = yes;" indicates that the first row contains columnnames, not data
Isn't there a CSV here? Oh, you can try it. The test results are very good. You can use ODBC to connect. Use CSV as a database,
It feels good. (oledb is not successful. If properties = text is changed to properties = CSV, It is not supported, or am I wrong ?)
Therefore, here is a method provided (not invented by me), using the ODBC connection method, directly using the dataadapter
Quick data import to dataset is convenient. The method is as follows:
Public dataset getdatasetfromcsv (string filepath, string filename)
{
String strconn = @ "driver = {Microsoft text Driver (*. txt; *. CSV)}; DBQ = ";
Strconn + = filepath; // filepath, for example: C :\
Strconn + = "; extensions = ASC, CSV, tab, txt ;";
Odbcconnection objconn = new odbcconnection (strconn );
Dataset dscsv = new dataset ();
Try
{
String strsql = "select * from" + filename; // filename, for example: 1.csv
Odbcdataadapter odbccsvdataadapter = new odbcdataadapter (strsql, objconn );
Odbccsvdataadapter. Fill (dscsv );
Return dscsv;
}
Catch (exception ex)
{
Throw ex;
}
}