Пример #1
0
        /// <summary>
        /// Submits an SQL query that expects a single record as a result, then returns the first record found
        /// </summary>
        /// <param name="strSQL">The select query</param>
        /// <returns>REturns the first row of the record set</returns>
        public DataRecord SelectQueryOneRecord(string strSQL)
        {
            SqlDataReader odbRead;
            SqlCommand    odbCommand;
            DataRecord    oRecord;
            int           iCtr;
            string        strName;

            CheckConnection();

            oRecord = new DataRecord();

            odbCommand = new SqlCommand(strSQL, cdbConn);
            odbCommand.CommandTimeout = cTimeoutSecs;
            odbRead = odbCommand.ExecuteReader();

            if (odbRead.HasRows == false)
            {
                oRecord.AddValue("FoundInDB", false);
                odbRead.Close();
                throw new Exception("The SQL query given retrned 0 rows.  The query was:\n" + strSQL);
            }

            odbRead.Read();
            oRecord.AddValue("FoundInDB", true);
            for (iCtr = 0; iCtr < odbRead.FieldCount; iCtr++)
            {
                strName = odbRead.GetName(iCtr);

                oRecord.AddValue(strName, odbRead[strName].ToString());
            }

            odbRead.Close();
            return(oRecord);
        }
Пример #2
0
        /// <summary>
        /// Submits an SQL query that expects multiple records as a result
        /// </summary>
        /// <param name="strSQL">The select query</param>
        /// <returns>Returns an enumerated list of DataRecords, each DataRecord is one row from the results</returns>
        public IEnumerable <DataRecord> SelectQueryMultipleRecords(string strSQL)
        {
            SqlDataReader     odbRead;
            SqlCommand        odbCommand;
            int               iCtr;
            string            strName;
            List <DataRecord> lRecords;
            DataRecord        oNewRecord;

            CheckConnection();

            lRecords   = new List <DataRecord>();
            odbCommand = new SqlCommand(strSQL, cdbConn);
            odbCommand.CommandTimeout = cTimeoutSecs;
            odbRead = odbCommand.ExecuteReader();

            if (odbRead.HasRows == false)
            {
                odbRead.Close();
                throw new Exception("The SQL query given retrned 0 rows.  The query was:\n" + strSQL);
            }

            while (odbRead.Read() == true)
            {
                oNewRecord = new DataRecord();

                oNewRecord.AddValue("FoundInDB", true);
                for (iCtr = 0; iCtr < odbRead.FieldCount; iCtr++)
                {
                    strName = odbRead.GetName(iCtr);

                    oNewRecord.AddValue(strName, odbRead[strName].ToString());
                }

                lRecords.Add(oNewRecord);
            }

            odbRead.Close();

            return(lRecords);
        }
Пример #3
0
		/// <summary>
		/// Submits an SQL query that expects a single record as a result, then returns the first record found
		/// </summary>
		/// <param name="strSQL">The select query</param>
		/// <returns>REturns the first row of the record set</returns>
		public DataRecord SelectQueryOneRecord(string strSQL) {
			SqlDataReader odbRead;
			SqlCommand odbCommand;
			DataRecord oRecord;
			int iCtr;
			string strName;

			CheckConnection();

			oRecord = new DataRecord();

			odbCommand = new SqlCommand(strSQL, cdbConn);
			odbCommand.CommandTimeout = cTimeoutSecs;
			odbRead = odbCommand.ExecuteReader();

			if (odbRead.HasRows == false) {
				oRecord.AddValue("FoundInDB", false);
				odbRead.Close();
				throw new Exception("The SQL query given retrned 0 rows.  The query was:\n" + strSQL);
			}

			odbRead.Read();
			oRecord.AddValue("FoundInDB", true);
			for (iCtr = 0; iCtr < odbRead.FieldCount; iCtr++) {
				strName = odbRead.GetName(iCtr);

				oRecord.AddValue(strName, odbRead[strName].ToString());
			}

			odbRead.Close();
			return oRecord;
		}
Пример #4
0
		/// <summary>
		/// Submits an SQL query that expects multiple records as a result
		/// </summary>
		/// <param name="strSQL">The select query</param>
		/// <returns>Returns an enumerated list of DataRecords, each DataRecord is one row from the results</returns>
		public IEnumerable<DataRecord> SelectQueryMultipleRecords(string strSQL) {
			SqlDataReader odbRead;
			SqlCommand odbCommand;
			int iCtr;
			string strName;
			List<DataRecord> lRecords;
			DataRecord oNewRecord;

			CheckConnection();

			lRecords = new List<DataRecord>();
			odbCommand = new SqlCommand(strSQL, cdbConn);
			odbCommand.CommandTimeout = cTimeoutSecs;
			odbRead = odbCommand.ExecuteReader();

			if (odbRead.HasRows == false) {
				odbRead.Close();
				throw new Exception("The SQL query given retrned 0 rows.  The query was:\n" + strSQL);
			}

			while (odbRead.Read() == true) {
				oNewRecord = new DataRecord();

				oNewRecord.AddValue("FoundInDB", true);
				for (iCtr = 0; iCtr < odbRead.FieldCount; iCtr++) {
					strName = odbRead.GetName(iCtr);

					oNewRecord.AddValue(strName, odbRead[strName].ToString());
				}

				lRecords.Add(oNewRecord);
			}

			odbRead.Close();

			return lRecords;
		}