|
@@ -21,13 +21,14 @@ namespace CnasSynchronusDAL |
|
|
public static Dictionary<string, DataTable> ReadAccessTables(string strPath, string strPwd,string strAccessVersion) |
|
|
public static Dictionary<string, DataTable> ReadAccessTables(string strPath, string strPwd,string strAccessVersion) |
|
|
{ |
|
|
{ |
|
|
Dictionary<string, DataTable> dictTables = new Dictionary<string, DataTable>(); |
|
|
Dictionary<string, DataTable> dictTables = new Dictionary<string, DataTable>(); |
|
|
|
|
|
OleDbConnection conn = null; |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
//连接字符串 |
|
|
//连接字符串 |
|
|
string connstring = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Persist Security Info=False;Jet OLEDB:Database Password={1}", strPath, strPwd); |
|
|
string connstring = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Persist Security Info=False;Jet OLEDB:Database Password={1}", strPath, strPwd); |
|
|
if(!string.IsNullOrWhiteSpace(strAccessVersion)&&strAccessVersion != "0") |
|
|
if(!string.IsNullOrWhiteSpace(strAccessVersion)&&strAccessVersion != "0") |
|
|
connstring = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=False;Jet OLEDB:Database Password={1}", strPath, strPwd); |
|
|
connstring = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=False;Jet OLEDB:Database Password={1}", strPath, strPwd); |
|
|
using (OleDbConnection conn = new OleDbConnection(connstring)) |
|
|
|
|
|
|
|
|
using (conn = new OleDbConnection(connstring)) |
|
|
{ |
|
|
{ |
|
|
conn.Open(); |
|
|
conn.Open(); |
|
|
DataTable TablesName = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "Table" }); //得到所有sheet的名字 |
|
|
DataTable TablesName = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "Table" }); //得到所有sheet的名字 |
|
@@ -50,19 +51,26 @@ namespace CnasSynchronusDAL |
|
|
//发生异常,写入日志 |
|
|
//发生异常,写入日志 |
|
|
AppLog.Error(ex.Message); |
|
|
AppLog.Error(ex.Message); |
|
|
} |
|
|
} |
|
|
|
|
|
finally |
|
|
|
|
|
{ |
|
|
|
|
|
conn?.Close(); |
|
|
|
|
|
conn?.Dispose(); |
|
|
|
|
|
} |
|
|
return dictTables; |
|
|
return dictTables; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
internal static DataTable ReadAccessTableStruct(string strPath, string strPwd, string strAccessVersion, string strViewName, string strViewSQL,string strTableName) |
|
|
internal static DataTable ReadAccessTableStruct(string strPath, string strPwd, string strAccessVersion, string strViewName, string strViewSQL,string strTableName) |
|
|
{ |
|
|
{ |
|
|
DataTable dt = new DataTable(); |
|
|
DataTable dt = new DataTable(); |
|
|
|
|
|
OleDbConnection conn = null; |
|
|
|
|
|
OleDbDataAdapter ada = null; |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
//连接字符串 |
|
|
//连接字符串 |
|
|
string connstring = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Persist Security Info=False;Jet OLEDB:Database Password={1}", strPath, strPwd); |
|
|
string connstring = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Persist Security Info=False;Jet OLEDB:Database Password={1}", strPath, strPwd); |
|
|
if (!string.IsNullOrWhiteSpace(strAccessVersion) && strAccessVersion != "0") |
|
|
if (!string.IsNullOrWhiteSpace(strAccessVersion) && strAccessVersion != "0") |
|
|
connstring = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=False;Jet OLEDB:Database Password={1}", strPath, strPwd); |
|
|
connstring = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=False;Jet OLEDB:Database Password={1}", strPath, strPwd); |
|
|
using (OleDbConnection conn = new OleDbConnection(connstring)) |
|
|
|
|
|
|
|
|
using (conn = new OleDbConnection(connstring)) |
|
|
{ |
|
|
{ |
|
|
conn.Open(); |
|
|
conn.Open(); |
|
|
|
|
|
|
|
@@ -78,7 +86,7 @@ namespace CnasSynchronusDAL |
|
|
else |
|
|
else |
|
|
sql = string.Format("select * from [{0}] where 1=0", strTableName); //查询字符串 |
|
|
sql = string.Format("select * from [{0}] where 1=0", strTableName); //查询字符串 |
|
|
|
|
|
|
|
|
using (OleDbDataAdapter ada = new OleDbDataAdapter(sql, connstring)) |
|
|
|
|
|
|
|
|
using (ada = new OleDbDataAdapter(sql, connstring)) |
|
|
{ |
|
|
{ |
|
|
DataSet set = new DataSet(); |
|
|
DataSet set = new DataSet(); |
|
|
ada.Fill(set); |
|
|
ada.Fill(set); |
|
@@ -91,6 +99,12 @@ namespace CnasSynchronusDAL |
|
|
//发生异常,写入日志 |
|
|
//发生异常,写入日志 |
|
|
AppLog.Error(ex.Message); |
|
|
AppLog.Error(ex.Message); |
|
|
} |
|
|
} |
|
|
|
|
|
finally |
|
|
|
|
|
{ |
|
|
|
|
|
ada?.Dispose(); |
|
|
|
|
|
conn?.Close(); |
|
|
|
|
|
conn?.Dispose(); |
|
|
|
|
|
} |
|
|
return dt; |
|
|
return dt; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -98,6 +112,8 @@ namespace CnasSynchronusDAL |
|
|
{ |
|
|
{ |
|
|
DataTable dt = new DataTable(); |
|
|
DataTable dt = new DataTable(); |
|
|
OleDbConnection conn = null; |
|
|
OleDbConnection conn = null; |
|
|
|
|
|
OleDbCommand command = null; |
|
|
|
|
|
OleDbDataReader reader = null; |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
AppLog.Info("开始执行"); |
|
|
AppLog.Info("开始执行"); |
|
@@ -120,13 +136,13 @@ namespace CnasSynchronusDAL |
|
|
using (conn = new OleDbConnection(connstring)) |
|
|
using (conn = new OleDbConnection(connstring)) |
|
|
{ |
|
|
{ |
|
|
conn.Open(); |
|
|
conn.Open(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取数据库表结构 |
|
|
//获取数据库表结构 |
|
|
DataTable dtStruct = new DataTable(); |
|
|
DataTable dtStruct = new DataTable(); |
|
|
dtStruct = ReadAccessTableStruct(strPath, strPwd, strAccessVersion, strViewName, strViewSQL, strTableName); |
|
|
dtStruct = ReadAccessTableStruct(strPath, strPwd, strAccessVersion, strViewName, strViewSQL, strTableName); |
|
|
|
|
|
|
|
|
//获取数据,并插入到表中 |
|
|
//获取数据,并插入到表中 |
|
|
using (OleDbCommand command = new OleDbCommand(sql, conn)) |
|
|
|
|
|
|
|
|
using (command = new OleDbCommand(sql, conn)) |
|
|
{ |
|
|
{ |
|
|
if (strViewName != strTableName || string.IsNullOrWhiteSpace(strViewName)) |
|
|
if (strViewName != strTableName || string.IsNullOrWhiteSpace(strViewName)) |
|
|
{ |
|
|
{ |
|
@@ -134,7 +150,7 @@ namespace CnasSynchronusDAL |
|
|
command.Parameters.AddWithValue("?", datetime); |
|
|
command.Parameters.AddWithValue("?", datetime); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
using (OleDbDataReader reader = command.ExecuteReader()) |
|
|
|
|
|
|
|
|
using (reader = command.ExecuteReader()) |
|
|
{ |
|
|
{ |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
@@ -170,6 +186,13 @@ namespace CnasSynchronusDAL |
|
|
//发生异常,写入日志 |
|
|
//发生异常,写入日志 |
|
|
AppLog.Error(ex.Message); |
|
|
AppLog.Error(ex.Message); |
|
|
} |
|
|
} |
|
|
|
|
|
finally |
|
|
|
|
|
{ |
|
|
|
|
|
reader?.Close(); |
|
|
|
|
|
command?.Dispose(); |
|
|
|
|
|
conn?.Close(); |
|
|
|
|
|
conn?.Dispose(); |
|
|
|
|
|
} |
|
|
return dt; |
|
|
return dt; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -191,17 +214,19 @@ namespace CnasSynchronusDAL |
|
|
public static DataTable ReadAccessTablesByTableName(string strPath, string strUser, string strPwd, string strTableName,string strAccessVersion) |
|
|
public static DataTable ReadAccessTablesByTableName(string strPath, string strUser, string strPwd, string strTableName,string strAccessVersion) |
|
|
{ |
|
|
{ |
|
|
DataSet set = new DataSet(); |
|
|
DataSet set = new DataSet(); |
|
|
|
|
|
OleDbConnection conn = null; |
|
|
|
|
|
OleDbDataAdapter ada = null; |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
//连接字符串 |
|
|
//连接字符串 |
|
|
string connstring = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Persist Security Info=False;Jet OLEDB:Database Password={1}", strPath, strPwd); |
|
|
string connstring = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Persist Security Info=False;Jet OLEDB:Database Password={1}", strPath, strPwd); |
|
|
if (!string.IsNullOrWhiteSpace(strAccessVersion) && strAccessVersion != "0") |
|
|
if (!string.IsNullOrWhiteSpace(strAccessVersion) && strAccessVersion != "0") |
|
|
connstring = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=False;Jet OLEDB:Database Password={1}", strPath, strPwd); |
|
|
connstring = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=False;Jet OLEDB:Database Password={1}", strPath, strPwd); |
|
|
using (OleDbConnection conn = new OleDbConnection(connstring)) |
|
|
|
|
|
|
|
|
using (conn = new OleDbConnection(connstring)) |
|
|
{ |
|
|
{ |
|
|
conn.Open(); |
|
|
conn.Open(); |
|
|
string sql = string.Format("SELECT * FROM [{0}]", strTableName); //查询字符串 |
|
|
string sql = string.Format("SELECT * FROM [{0}]", strTableName); //查询字符串 |
|
|
using (OleDbDataAdapter ada = new OleDbDataAdapter(sql, connstring)) |
|
|
|
|
|
|
|
|
using (ada = new OleDbDataAdapter(sql, connstring)) |
|
|
{ |
|
|
{ |
|
|
ada.Fill(set); |
|
|
ada.Fill(set); |
|
|
} |
|
|
} |
|
@@ -212,6 +237,12 @@ namespace CnasSynchronusDAL |
|
|
//发生异常,写入日志 |
|
|
//发生异常,写入日志 |
|
|
AppLog.Error(ex.Message); |
|
|
AppLog.Error(ex.Message); |
|
|
} |
|
|
} |
|
|
|
|
|
finally |
|
|
|
|
|
{ |
|
|
|
|
|
ada?.Dispose(); |
|
|
|
|
|
conn?.Close(); |
|
|
|
|
|
conn?.Dispose(); |
|
|
|
|
|
} |
|
|
return set.Tables[0]; |
|
|
return set.Tables[0]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|