dachelper.cs

来自「usb-com for sms 自己开发的类 可以借鉴下」· CS 代码 · 共 84 行

CS
84
字号
using System;
using System.Data;
using System.Data.SqlClient;

namespace IPP.SMS
{
	/// <summary>
	/// Summary description for DacHelper.
	/// </summary>
	public class DacHelper
	{
		private SqlCommand _command = null;
		private string _connectionString = AppConst.ConnectionString;

		public DacHelper(string paramCommandText, CommandType paramCommandType) 
		{
			_command = new SqlCommand(paramCommandText);
			_command.CommandType = paramCommandType;
		}
		public DacHelper(string paramCommandText)
		{
			_command = new SqlCommand(paramCommandText);
			_command.CommandType =CommandType.Text;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="paramDataSetName"></param>
		/// <returns></returns>
		public DataSet ExecuteDataSet(string paramDataSetName)
		{
			DataSet ds;
			SqlConnection con = new SqlConnection(_connectionString);
			try
			{
				con.Open();
				_command.Connection = con;
				SqlDataAdapter sqlDA = new SqlDataAdapter();
				sqlDA.SelectCommand = _command;
				ds = new DataSet();
				sqlDA.Fill( ds, paramDataSetName );
			}
			catch(Exception exp)
			{
				
				throw exp;
			}
			finally
			{
				con.Close();
			}
			return ds;
		}
		public int ExecuteNoQuery()
		{
			int result = AppConst.IntNull;
			SqlConnection con = new SqlConnection(_connectionString);
			try
			{
				con.Open();
				_command.Connection = con;
				result = _command.ExecuteNonQuery();
			}
			catch(Exception exp)
			{
				
				throw exp;
			}
			finally
			{
				con.Close();
			}

			return result;
		}

		public SqlCommand Command 
		{
			get { return _command; }
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?