/// <summary> /// ���ݲ�ѯ���������Ķ������� /// </summary> /// <param name="SQL">SQL</param> /// <param name="commandType">��������</param> /// <param name="cmdBehavior">�Բ�ѯ�ͷ��ؽ����Ӱ���˵��</param> /// <param name="parameters">��������</param> /// <returns>�����Ķ���</returns> protected virtual IDataReader ExecuteDataReader(ref string SQL, CommandType commandType, CommandBehavior cmdBehavior,ref IDataParameter[] parameters) { IDbConnection conn=GetConnection(); IDbCommand cmd=conn.CreateCommand (); CompleteCommand(cmd,ref SQL,ref commandType,ref parameters); DMEDb_CommandLog cmdLog = new DMEDb_CommandLog(true); IDataReader reader=null; try { //������������������Ϊ�գ���ôǿ���ڶ�ȡ�����ݺ�ر��Ķ��������ݿ����� 2008.3.20 if(cmd.Transaction ==null && cmdBehavior==CommandBehavior.Default ) cmdBehavior=CommandBehavior.CloseConnection ; reader = cmd.ExecuteReader (cmdBehavior); } catch(Exception ex) { ErrorMessage=ex.Message ; //ֻ�г����˴������û�п��������Թر����� if(cmd.Transaction==null && conn.State ==ConnectionState.Open ) conn.Close (); bool inTransaction = cmd.Transaction == null ? false : true; cmdLog.WriteErrLog(cmd, "DMEDb_AdoHelper:" + ErrorMessage); if (OnErrorThrow) { throw new DMEDb_QueryException(ex.Message, cmd.CommandText, commandType, parameters, inTransaction, conn.ConnectionString); } } cmdLog.WriteLog(cmd, "DMEDb_AdoHelper", out _elapsedMilliseconds); return reader; }
/// <summary> /// ִ�в������ݵIJ�ѯ��������Access��SqlServer /// </summary> /// <param name="SQL">�������ݵ�SQL</param> /// <param name="commandType">��������</param> /// <param name="parameters">��������</param> /// <param name="ID">Ҫ�����ı��β������²��������е�����IDֵ</param> /// <returns>���β�ѯ��Ӱ�������</returns> public virtual int ExecuteInsertQuery(string SQL,CommandType commandType,IDataParameter[] parameters,ref object ID) { IDbConnection conn=GetConnection(); IDbCommand cmd=conn.CreateCommand (); CompleteCommand(cmd,ref SQL,ref commandType,ref parameters); DMEDb_CommandLog cmdLog = new DMEDb_CommandLog(true); bool inner=false; int result=-1; ID=0; try { if(cmd.Transaction ==null) { inner=true; cmd.Transaction=conn.BeginTransaction (); } result=cmd.ExecuteNonQuery (); cmd.CommandText = this.InsertKey;// "SELECT @@IDENTITY"; ID=cmd.ExecuteScalar (); //������ڲ��������������ύ�������ⲿ�����߾�����ʱ�ύ���� if(inner) { cmd.Transaction.Commit (); cmd.Transaction=null; } } catch(Exception ex) { ErrorMessage=ex.Message ; bool inTransaction = cmd.Transaction == null ? false : true; if(cmd.Transaction!=null) cmd.Transaction.Rollback (); if(inner) cmd.Transaction=null; cmdLog.WriteErrLog(cmd, "DMEDb_AdoHelper:" + ErrorMessage); if (OnErrorThrow) { throw new DMEDb_QueryException(ex.Message, cmd.CommandText , commandType, parameters, inTransaction, conn.ConnectionString); } } finally { if(cmd.Transaction==null && conn.State ==ConnectionState.Open ) conn.Close (); } cmdLog.WriteLog(cmd, "DMEDb_AdoHelper", out _elapsedMilliseconds); return result; }
/// <summary> /// ִ�з��ص�һֵ�ò�ѯ /// </summary> /// <param name="SQL">SQL</param> /// <param name="commandType">��������</param> /// <param name="parameters">��������</param> /// <returns>��ѯ���</returns> public virtual object ExecuteScalar(string SQL,CommandType commandType,IDataParameter[] parameters) { IDbConnection conn=GetConnection(); IDbCommand cmd=conn.CreateCommand (); CompleteCommand(cmd,ref SQL,ref commandType,ref parameters); DMEDb_CommandLog cmdLog = new DMEDb_CommandLog(true); object result=null; try { result=cmd.ExecuteScalar (); //����������������ϲ�����߾�����ʱ�ύ���� } catch(Exception ex) { ErrorMessage =ex.Message ; //�������������ô�˴�Ӧ�û������� //if(cmd.Transaction!=null) // cmd.Transaction.Rollback (); bool inTransaction = cmd.Transaction == null ? false : true; cmdLog.WriteErrLog(cmd, "DMEDb_AdoHelper:" + ErrorMessage); if (OnErrorThrow) { throw new DMEDb_QueryException(ex.Message, cmd.CommandText, commandType, parameters, inTransaction, conn.ConnectionString); } } finally { if(cmd.Transaction==null && conn.State ==ConnectionState.Open ) conn.Close (); } cmdLog.WriteLog(cmd, "DMEDb_AdoHelper", out _elapsedMilliseconds); return result; }
/// <summary> /// ִ�з������ݼ��IJ�ѯ /// </summary> /// <param name="SQL">SQL</param> /// <param name="commandType">��������</param> /// <param name="parameters">��������</param> /// <returns>���ݼ�</returns> public virtual DataSet ExecuteDataSet(string SQL,CommandType commandType,IDataParameter[] parameters) { IDbConnection conn=GetConnection(); IDbCommand cmd=conn.CreateCommand (); CompleteCommand(cmd,ref SQL,ref commandType,ref parameters); IDataAdapter ada=GetDataAdapter(cmd); DMEDb_CommandLog cmdLog = new DMEDb_CommandLog(true); DataSet ds=new DataSet (); try { ada.Fill(ds);//FillSchema(ds,SchemaType.Mapped ) } catch(Exception ex) { ErrorMessage=ex.Message ; bool inTransaction = cmd.Transaction == null ? false : true; cmdLog.WriteErrLog(cmd, "DMEDb_AdoHelper:" + ErrorMessage); if (OnErrorThrow) { throw new DMEDb_QueryException(ex.Message, cmd.CommandText, commandType, parameters, inTransaction, conn.ConnectionString); } } finally { if(cmd.Transaction==null && conn.State ==ConnectionState.Open ) conn.Close (); } cmdLog.WriteLog(cmd, "DMEDb_AdoHelper", out _elapsedMilliseconds); return ds; }