Files
U8-Import/NX.ERP.U8/AdoHelper.cs

139 lines
2.8 KiB
C#
Raw Normal View History

2021-01-05 16:49:51 +08:00
using ADODB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NX.ERP.U8
{
public class AdoHelper : IDisposable
{
private ADODB.Connection connection;
public Connection Connection { get => connection; set => connection = value; }
public void BeginTrans()
{
try
{
if (Connection != null)
{
Connection.BeginTrans();
}
}
catch (Exception)
{
throw;
}
}
public AdoHelper(string constr)
{
if (!string.IsNullOrEmpty(constr))
{
connection = new ConnectionClass();
connection.ConnectionString = constr;
try
{
connection.Open();
}
catch (Exception err)
{
throw new Exception(err.Message);
}
}
else
{
throw new Exception("链接字符串为空");
}
}
public Recordset U8ExcuteRecord(string strSQL)
{
try
{
return connection.Execute(strSQL, out object RecordsAffected);
}
catch (Exception)
{
throw;
}
}
public int ExcuteNoneQuery(string strSQL)
{
try
{
Connection.Execute(strSQL, out var RecordsAffected);
return (int)RecordsAffected;
}
catch (Exception)
{
throw;
}
}
public void RollbackTrans()
{
try
{
if (Connection != null)
{
Connection.RollbackTrans();
}
}
catch (Exception)
{
throw;
}
}
public void CommitTrans()
{
try
{
if (Connection != null)
{
Connection.CommitTrans();
}
}
catch (Exception)
{
throw;
}
}
public void Dispose()
{
try
{
if (Connection != null)
{
if (Connection.State == 1)
{
Connection.Close();
}
Connection = null;
}
}
catch (Exception)
{
throw;
}
}
}
}