public void OnResult(bool bAutoTrans, RecordStyle eRecordStyle) { try { this.DataCenter.GetResult(eRecordStyle); if (this.bUseTrans) { this.DataCenter.DoTrans(true); } } catch (Exception ex) { this.strMessage = ex.Message; } }
/// <summary> /// 获取记录集 /// </summary> /// <param name="eRecordStyle">记录集样式</param> public void GetResult(RecordStyle eRecordStyle) { DataSet pDataSet = new DataSet(); MySqlDataAdapter pDataAdapter = null; try { //枚举纪录集 switch (eRecordStyle) { #region 影响行数 case RecordStyle.NONE: this.iAffectRow = this.pCommand.ExecuteNonQuery(); break; #endregion #region DataSet 式数据集 case RecordStyle.DATASET: pDataAdapter = new MySqlDataAdapter(pCommand); pDataAdapter.Fill(pDataSet); this.iAffectRow = pDataSet.Tables[0].Rows.Count; this.pDataResult = pDataSet; break; #endregion } } catch (SqlException ex) { this.iAffectRow = -1; this.strErrorMsg = ex.Message; } finally { pDataSet = null; this.pCommand.Dispose(); this.pCommand = null; } }
/// <summary> /// 获取记录集 /// </summary> /// <param name="eRecordStyle"></param> public abstract void GetResult(RecordStyle eRecordStyle);
public override void GetResult(RecordStyle eRecordStyle) { DataSet pDataSet = new DataSet(); try { switch (eRecordStyle) { #region 影响行数 case RecordStyle.NONE: this.iAffectRow = this.pCommand.ExecuteNonQuery(); break; #endregion #region 自定义结构 -- case RecordStyle.STRUCT: throw new ArgumentException("获取记录集失败:", "不是有效的记录集"); #endregion #region DataSet结果集 case RecordStyle.DATASET: SqlDataAdapter pDataAdapter = new SqlDataAdapter(this.pCommand); //pCommand.StatementCompleted += new StatementCompletedEventHandler(pCommand_StatementCompleted); pDataAdapter.Fill(pDataSet); this.iAffectRow = pDataSet.Tables[0].Rows.Count; this.pExecuteResult = pDataSet; //pDataSet.Clear(); break; #endregion #region DataTable结果集 case RecordStyle.DATATABLE: SqlDataAdapter pTableAdapter = new SqlDataAdapter(this.pCommand); pTableAdapter.Fill(pDataSet); this.iAffectRow = 0; this.pExecuteResult = DataUtilities.MergeTable(pDataSet); pDataSet.Clear(); break; #endregion #region XML数据流 case RecordStyle.XML: MemoryStream pXMLStream = new MemoryStream(); SqlDataReader pXMLReader = this.pCommand.ExecuteReader(CommandBehavior.CloseConnection); DataTable pXMLTable = new DataTable(); pXMLTable.Load(pXMLReader, LoadOption.Upsert); pXMLTable.WriteXml(pXMLStream); this.iAffectRow = -1; this.pExecuteResult = pXMLStream.GetBuffer(); pXMLStream.Close(); pXMLReader.Close(); break; #endregion #region 自定义数据文件 case RecordStyle.DATAFILE: this.pCommand.BeginExecuteReader(new AsyncCallback(DataFileCallback), new RecordDataCallback(this.SocketConnection, this.eService, this.pCommand), CommandBehavior.CloseConnection); break; #endregion #region 实时数据 case RecordStyle.REALTIME: this.pCommand.BeginExecuteReader(new AsyncCallback(RealTimeCallback), new RecordDataCallback(this.SocketConnection, this.eService, this.pCommand), CommandBehavior.CloseConnection); break; #endregion #region 未知结果样式 default: throw new ArgumentException("获取记录集失败:", "不是有效的记录集"); #endregion } } catch (InvalidOperationException ex) { this.iAffectRow = -1; this.strErrorMsg = ex.Message; } catch (SqlException ex) { this.iAffectRow = -1; this.strErrorMsg = ex.Message; } catch (Exception ex) { this.iAffectRow = -1; this.strErrorMsg = ex.Message; } finally { pDataSet = null; this.pCommand.Dispose(); this.pCommand = null; } }
public void OnResult(RecordStyle eRecordStyle) { this.pDataOperate.GetResult(eRecordStyle); }