private clsResponse _GetTableList(string pWhere) { clsResponse response = new clsResponse(); string SQL = "SELECT name FROM sys.objects"; SQL += " where type = 'U'"; if (pWhere.Length > 0) { SQL += " and name like " + "'" + pWhere + "'"; } SQL += " order by name"; response = _Select(SQL); if (response.xHasError) { } else { DataTable dt = new DataTable(); dt.Columns.Add("テーブル名", typeof(string)); for (int i = 0; i < response.xGetDataTable(0).Rows.Count; i++) { DataRow row = dt.NewRow(); row["テーブル名"] = response.xGetDataTable(0).Rows[i]["name"].ToString(); dt.Rows.Add(row); } response = new clsResponse(); response.xAddDataTable(dt); } return response; }
private clsResponse _ReaderRead() { clsResponse response = new clsResponse(); string msg = ""; DataTable dt = null; try { if (myReader_.Read()) { if (myTable_ == null) { myTable_ = new DataTable(); dt = myReader_.GetSchemaTable(); DataColumn column = null; for (int i = 0; i < dt.Rows.Count; i++) { column = new DataColumn(); column.ColumnName = dt.Rows[i]["ColumnName"].ToString(); column.DataType = Type.GetType(dt.Rows[i]["DataType"].ToString()); myTable_.Columns.Add(column); } } dt = myTable_.Clone(); DataRow row = dt.NewRow(); for (int i = 0; i < myReader_.FieldCount; i++) { row[i] = myReader_[i]; } dt.Rows.Add(row); response.xAddDataTable(dt); } else { response.xSetReturn("EOF", "True"); _ReaderClose(); return response; } } catch (Exception ex) { msg = "DataReaderからの読み込みに失敗しました。"; msg += ex.Message + Environment.NewLine; response.xSetError(msg); msg += ex.StackTrace; ////////clsTextLogger.xWriteTextLog( //////// MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + //////// MethodBase.GetCurrentMethod().Name, msg); _ReaderClose(); return response; } return response; }
private clsResponse _Select(string pSQL) { clsResponse response = new clsResponse(); ////OleDbDataAdapter da = null; NpgsqlDataAdapter da = null; DataTable dt = null; string msg = ""; int count = 0; ////OleDbCommand command = new OleDbCommand(); NpgsqlCommand command = new NpgsqlCommand(); command.Connection = this.myConnection_; command.Transaction = this.myTransaction_; command.CommandText = pSQL; command.CommandType = CommandType.Text; // 2018/01/13 command.CommandTimeout = 300; try { ////da = new OleDbDataAdapter(command); da = new NpgsqlDataAdapter(command); dt = new DataTable(); count = da.Fill(dt); response.xAddDataTable(dt); // 2017/12/13 K.Nakamura ////////msg = "SQL=" + pSQL; ////////clsTextLogger.xWriteTextLog( //////// MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + //////// MethodBase.GetCurrentMethod().Name, msg); ////////msg = "取得件数=" + count.ToString("#,##0 件"); ////////clsTextLogger.xWriteTextLog( //////// MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + //////// MethodBase.GetCurrentMethod().Name, msg); } catch (Exception ex) { msg = "SELECTに失敗しました。"; msg += "(" + myDBInfo_.xDBName + ")" + "(" + pSQL + ")" + Environment.NewLine; msg += ex.Message + Environment.NewLine; response.xSetError(msg); msg += ex.StackTrace; ////////clsTextLogger.xWriteTextLog( //////// MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + //////// MethodBase.GetCurrentMethod().Name, msg); } finally { response.xSetReturn("-- ResultCount", count.ToString()); if (command != null) { command.Connection = null; command.Transaction = null; command.Dispose(); command = null; } if (da != null) { da.Dispose(); da = null; } if (dt != null) { dt.Rows.Clear(); dt.Columns.Clear(); dt.Dispose(); dt = null; } } return response; }