Update AccessCore

This commit is contained in:
sunkaixuan 2024-07-15 13:49:54 +08:00
parent 103b69c9b4
commit ec7fb113a9
2 changed files with 149 additions and 2 deletions

View File

@ -58,7 +58,7 @@ namespace SqlSugar.Access
}
public override IDataAdapter GetAdapter()
{
return new OleDbDataAdapter();
return new OleDbDataAdapterNew();
}
public override DbCommand GetCommand(string sql, SugarParameter[] parameters)
{
@ -84,7 +84,7 @@ namespace SqlSugar.Access
}
public override void SetCommandToAdapter(IDataAdapter dataAdapter, DbCommand command)
{
((OleDbDataAdapter)dataAdapter).SelectCommand = (OleDbCommand)command;
((OleDbDataAdapterNew)dataAdapter).SelectCommand = (OleDbCommand)command;
}
/// <summary>
/// if mysql return MySqlParameter[] pars

View File

@ -0,0 +1,147 @@
using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Data;
using System.Text;
namespace SqlSugar
{
/// <summary>
/// 数据填充器
/// </summary>
public class OleDbDataAdapterNew : IDataAdapter
{
private OleDbCommand command;
private string sql;
private OleDbConnection _sqlConnection;
/// <summary>
/// SqlDataAdapter
/// </summary>
/// <param name="command"></param>
public OleDbDataAdapterNew(OleDbCommand command)
{
this.command = command;
}
public OleDbDataAdapterNew()
{
}
/// <summary>
/// SqlDataAdapter
/// </summary>
/// <param name="sql"></param>
/// <param name="_sqlConnection"></param>
public OleDbDataAdapterNew(string sql, OleDbConnection _sqlConnection)
{
this.sql = sql;
this._sqlConnection = _sqlConnection;
}
/// <summary>
/// SelectCommand
/// </summary>
public OleDbCommand SelectCommand
{
get
{
if (this.command == null)
{
this.command = new OleDbCommand(this.sql, this._sqlConnection);
}
return this.command;
}
set
{
this.command = value;
}
}
/// <summary>
/// Fill
/// </summary>
/// <param name="dt"></param>
public void Fill(DataTable dt)
{
if (dt == null)
{
dt = new DataTable();
}
var columns = dt.Columns;
var rows = dt.Rows;
using (OleDbDataReader dr = command.ExecuteReader())
{
for (int i = 0; i < dr.FieldCount; i++)
{
string name = dr.GetName(i).Trim();
if (!columns.Contains(name))
columns.Add(new DataColumn(name, dr.GetFieldType(i)));
else
{
columns.Add(new DataColumn(name + i, dr.GetFieldType(i)));
}
}
while (dr.Read())
{
DataRow daRow = dt.NewRow();
for (int i = 0; i < columns.Count; i++)
{
daRow[columns[i].ColumnName] = dr.GetValue(i);
}
dt.Rows.Add(daRow);
}
}
dt.AcceptChanges();
}
/// <summary>
/// Fill
/// </summary>
/// <param name="ds"></param>
public void Fill(DataSet ds)
{
if (ds == null)
{
ds = new DataSet();
}
using (OleDbDataReader dr = command.ExecuteReader())
{
do
{
var dt = new DataTable();
var columns = dt.Columns;
var rows = dt.Rows;
for (int i = 0; i < dr.FieldCount; i++)
{
string name = dr.GetName(i).Trim();
if (!columns.Contains(name))
columns.Add(new DataColumn(name, dr.GetFieldType(i)));
else
{
columns.Add(new DataColumn(name + i, dr.GetFieldType(i)));
}
}
while (dr.Read())
{
DataRow daRow = dt.NewRow();
for (int i = 0; i < columns.Count; i++)
{
daRow[columns[i].ColumnName] = dr.GetValue(i);
}
dt.Rows.Add(daRow);
}
dt.AcceptChanges();
ds.Tables.Add(dt);
} while (dr.NextResult());
}
}
}
}