|
|
@ -6,7 +6,7 @@ using System.Text;
|
|
|
|
|
|
|
|
|
|
|
|
namespace AccessStudy.Core
|
|
|
|
namespace AccessStudy.Core
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class OledbUtil:IDisposable
|
|
|
|
public class OledbUtil : IDisposable
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public OleDbConnection DbConnection { get; set; }
|
|
|
|
public OleDbConnection DbConnection { get; set; }
|
|
|
|
|
|
|
|
|
|
|
@ -18,7 +18,7 @@ namespace AccessStudy.Core
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public OledbUtil(string connetString)
|
|
|
|
public OledbUtil(string connetString)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DbConnection = new OleDbConnection(connetString);
|
|
|
|
DbConnection = new OleDbConnection(connetString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -72,7 +72,7 @@ namespace AccessStudy.Core
|
|
|
|
|
|
|
|
|
|
|
|
adapter.Fill(dataSet);
|
|
|
|
adapter.Fill(dataSet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Console.WriteLine(ex.Message);
|
|
|
|
Console.WriteLine(ex.Message);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -87,7 +87,7 @@ namespace AccessStudy.Core
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 获取DataSet
|
|
|
|
/// 获取DataSet
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public DataSet GetDataSet(string sqlText, List<OleDbParameter> parameters=null)
|
|
|
|
public DataSet GetDataSet(string sqlText, List<OleDbParameter> parameters = null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DataSet dataSet = new DataSet();
|
|
|
|
DataSet dataSet = new DataSet();
|
|
|
|
try
|
|
|
|
try
|
|
|
@ -100,11 +100,11 @@ namespace AccessStudy.Core
|
|
|
|
CommandText = sqlText,
|
|
|
|
CommandText = sqlText,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (parameters !=null)
|
|
|
|
if (parameters != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
command.Parameters.AddRange(parameters.ToArray());
|
|
|
|
command.Parameters.AddRange(parameters.ToArray());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var adapter = new OleDbDataAdapter(command);
|
|
|
|
var adapter = new OleDbDataAdapter(command);
|
|
|
|
|
|
|
|
|
|
|
|
adapter.Fill(dataSet);
|
|
|
|
adapter.Fill(dataSet);
|
|
|
@ -133,9 +133,9 @@ namespace AccessStudy.Core
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 获取DataTable
|
|
|
|
/// 获取DataTable
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public DataTable GetDataTable(string sqlText, List<OleDbParameter> parameters=null)
|
|
|
|
public DataTable GetDataTable(string sqlText, List<OleDbParameter> parameters = null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DataSet dataSet = GetDataSet(sqlText,parameters);
|
|
|
|
DataSet dataSet = GetDataSet(sqlText, parameters);
|
|
|
|
return dataSet.Tables[0];
|
|
|
|
return dataSet.Tables[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -175,7 +175,7 @@ namespace AccessStudy.Core
|
|
|
|
/// 获取DataReader
|
|
|
|
/// 获取DataReader
|
|
|
|
/// 切记:用完之后主动关闭连接
|
|
|
|
/// 切记:用完之后主动关闭连接
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public OleDbDataReader GetDataReader(string sqlText, List<OleDbParameter> parameters=null)
|
|
|
|
public OleDbDataReader GetDataReader(string sqlText, List<OleDbParameter> parameters = null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OleDbDataReader dataReader = null;
|
|
|
|
OleDbDataReader dataReader = null;
|
|
|
|
try
|
|
|
|
try
|
|
|
@ -185,12 +185,12 @@ namespace AccessStudy.Core
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Connection = DbConnection,
|
|
|
|
Connection = DbConnection,
|
|
|
|
CommandType = CommandType.Text,
|
|
|
|
CommandType = CommandType.Text,
|
|
|
|
CommandText =sqlText,
|
|
|
|
CommandText = sqlText,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (parameters != null)
|
|
|
|
if (parameters != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
command.Parameters.Add(parameters.ToArray());
|
|
|
|
command.Parameters.AddRange(parameters.ToArray());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
dataReader = command.ExecuteReader();
|
|
|
|
dataReader = command.ExecuteReader();
|
|
|
@ -212,7 +212,7 @@ namespace AccessStudy.Core
|
|
|
|
/// 获取第一行第一列的值
|
|
|
|
/// 获取第一行第一列的值
|
|
|
|
/// 不存在则为null
|
|
|
|
/// 不存在则为null
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public object GetScalar(string sqlText, List<OleDbParameter> parameters=null)
|
|
|
|
public object GetScalar(string sqlText, List<OleDbParameter> parameters = null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
object result = null;
|
|
|
|
object result = null;
|
|
|
|
|
|
|
|
|
|
|
@ -228,14 +228,14 @@ namespace AccessStudy.Core
|
|
|
|
|
|
|
|
|
|
|
|
if (parameters != null)
|
|
|
|
if (parameters != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
command.Parameters.Add(parameters.ToArray());
|
|
|
|
command.Parameters.AddRange(parameters.ToArray());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
result = command.ExecuteScalar();
|
|
|
|
result = command.ExecuteScalar();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw ex;
|
|
|
|
throw ex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -265,7 +265,7 @@ namespace AccessStudy.Core
|
|
|
|
|
|
|
|
|
|
|
|
if (parameters != null)
|
|
|
|
if (parameters != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
command.Parameters.Add(parameters.ToArray());
|
|
|
|
command.Parameters.AddRange(parameters.ToArray());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
result = command.ExecuteNonQuery();
|
|
|
|
result = command.ExecuteNonQuery();
|
|
|
@ -306,7 +306,7 @@ namespace AccessStudy.Core
|
|
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (DbConnection.State==ConnectionState.Open)
|
|
|
|
if (DbConnection.State == ConnectionState.Open)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DbConnection.Close();
|
|
|
|
DbConnection.Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|