/// <summary>
/// 返回DataSet
/// </summary>
public DataSet ExeSqlDs(string strSql, int nStart, int nCount, string strTable)
{
m_strError = "";
DataSet ds = new DataSet();
OleDbDataAdapter oleDbAdapter = new OleDbDataAdapter(strSql,m_oleDbCnn);
try
{
oleDbAdapter.Fill(ds,nStart,nCount,strTable);
}
catch (OleDbException ex)
{
ds = null;
m_strError = ex.ToString();
}
return ds;
}
/// <summary>
/// 返回DataSet
/// </summary>
public DataSet ExeSqlDs(OleDbCommand oleDbCmd, string strTable)
{
m_strError = "";
DataSet ds = new DataSet();
oleDbCmd.Connection = m_oleDbCnn;
OleDbDataAdapter oleDbAdapter = new OleDbDataAdapter();
oleDbAdapter.SelectCommand = oleDbCmd;
try
{
oleDbAdapter.Fill(ds,strTable);
}
catch (OleDbException ex)
{
ds = null;
m_strError = ex.ToString();
}
return ds;
}
/// <summary>
/// //设定Connection 字符串,new cnn
/// </summary>
public void SetConnectionString(string strSource)
{
m_strCnn = strSource;
m_oleDbCnn = null;
m_oleDbCnn = new OleDbConnection(m_strCnn);
}
/// <summary>
/// 错误信息
/// </summary>
private string m_strError;
/// <summary>
/// 错误
/// </summary>
public string StrErrorInfo
{
get
{
return m_strError;
}
}
}
}
/*************************************************
SqlDb
**************************************************/
using System;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace Db
{
/// <summary>
///
/// </summary>
public class SqlDb
{
public SqlDb()
{
//
// TODO: 在此处添加构造函数逻辑
m_sqlCnn = null;
//
}
/// <summary>
/// Connection参数
/// </summary>
private string m_strCnn; // = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
private SqlConnection m_sqlCnn = null; //new SqlConnection(m_strCnn);
/// <summary>
/// 执行delete,insert,update等操作,返回值为影响的行数
/// </summary>
public int ExeNoQuery(string strSql)
{
int nRet = -1;
m_strError = "";
SqlCommand sqlCmd = new SqlCommand(strSql,m_sqlCnn);
try
{
OpenCnn();
nRet = sqlCmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
nRet = -1;
m_strError = ex.ToString();
}
finally
{
if (m_sqlCnn.State==ConnectionState.Open)
{
sqlCmd.Dispose();
m_sqlCnn.Close();
}
}
return nRet;
}