数据库连接字符串 - Text
ODBC DSN
// ODBC DSN
using System.Data.Odbc;
OdbcConnection conn = new OdbcConnection(); conn.ConnectionString = "Dsn=DsnName;" + "Uid=UserName;" + "Pwd=Secret;"; conn.Open(); |
ODBC without DSN
// ODBC without DSN
using System.Data.Odbc;
OdbcConnection conn = new OdbcConnection(); conn.ConnectionString = "Driver={Microsoft Text Driver (*.txt; *.csv)};" + "Dbq=C:/MyPath/;" + "Extensions=asc,csv,tab,txt;"; conn.Open();
// Use: sql = "Select * From MyTextFile.txt" |
OleDb with MS Jet
// OleDb with MS Jet
using System.Data.OleDb;
OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = "Driver=Microsoft.Jet.OLEDB.4.0;" + "Data Source=C:/MyPath/;" + "Extended Properties=" + @"""text;HDR=Yes;FMT=Delimited"""; conn.Open();
// Use: sql = "Select * From MyTextFile.txt" |