/// <summary>
/// 保存DataTable 到 表
/// </summary>
/// <param name="dt"></param>
/// <param name="tableName"></param>
/// <param name="isOpen"></param>
/// <param name="isDelete"></param>
/// <returns></returns>
public int SaveData(DataTable dt,string tableName,bool isOpen,bool isDelete)
{
DateTime begDate = DateTime.Now;
if (isOpen)
{
Open();
}
int count = 0;
string strSql = "select * from " + tableName;
try
{
if (!isDelete)
{
try
{
int delCount = ExecuteSQL("delete " + tableName);
outLog(LogFile.Import, "表名 【" + tableName + "】 记录数【" + delCount.ToString() + "】", begDate);
}
catch (Exception e)
{
LogManager.WriteLogs(LogFile.Error, "删除 表 " + tableName + " 错误:" + e.Message);
}
}
OracleDataAdapter adapter = new OracleDataAdapter(strSql, connString);
OracleCommandBuilder oracleCB = new OracleCommandBuilder(adapter);
//adapter.InsertCommand = oracleCB.GetInsertCommand();
DataTable dsNew = new DataTable();
count = adapter.Fill(dsNew);
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow dr = dsNew.NewRow();
for (int j = 0; j < dt.Columns.Count; j++)
{
dr[dsNew.Columns[j].ColumnName] = dt.Rows[i][j];
}
dsNew.Rows.Add(dr);
}
count = adapter.Update(dsNew);
outLog(LogFile.Import, "表名 【" + tableName + "】 记录数【" + dt.Rows.Count.ToString() + "】", begDate);
}
catch(Exception e)
{
LogManager.WriteLogs(LogFile.Error, "添加 表 " + tableName + " 错误:" + e.Message);
count = -1;
}
finally
{
if (isDelete)
{
Close();
}
}
return count;
}