示例#1
0
        public bool ExecuteProc(String strProcName, STableRecordSet RecordSets, params SqlParameter[] aryProcParams)
        {
            OpenDataBase();

            SqlCommand dbCmd = m_dbConnect.CreateCommand();

            dbCmd.CommandText = strProcName;
            dbCmd.CommandType = CommandType.StoredProcedure;

            if (aryProcParams != null)
            {
                dbCmd.Parameters.AddRange(aryProcParams); // Past the params
            }

            SqlDataReader dbReader = dbCmd.ExecuteReader();

            if (dbReader == null)
            {
                return(false);
            }

            //////////////////////////////////////////////////////////////////////////
            // Init data to SqlDataReader
            // Get Field names

            RecordSets.m_straFieldNames = new ArrayList();
            int nFieldCount = dbReader.FieldCount;

            for (int i = 0; i < nFieldCount; i++)
            {
                RecordSets.m_straFieldNames.Add(dbReader.GetName(i));
            }

            RecordSets.m_str2aRecords = new ArrayList();
            // Get Records
            while (dbReader.Read())
            {
                ArrayList aryRecord = new ArrayList(nFieldCount);

                for (int i = 0; i < nFieldCount; i++)
                {
                    aryRecord.Add(dbReader[i].ToString());
                }

                RecordSets.m_str2aRecords.Add(aryRecord);
            }
            dbReader.Close();

            return(true);
        }
示例#2
0
        public bool ExecuteSQL(String strSQL, STableRecordSet RecordSets)
        {
            OpenDataBase();

            if (RecordSets == null)
            {
                return(false);
            }

            RecordSets.m_straFieldNames = new ArrayList();

            SqlCommand dbCmd = m_dbConnect.CreateCommand();

            dbCmd.CommandText = strSQL;

            SqlDataReader dbReader = dbCmd.ExecuteReader();

            //////////////////////////////////////////////////////////////////////////
            // Init data to SqlDataReader
            // Get Field names
            int nFieldCount = dbReader.FieldCount;

            for (int i = 0; i < nFieldCount; i++)
            {
                RecordSets.m_straFieldNames.Add(dbReader.GetName(i));
            }

            RecordSets.m_str2aRecords = new ArrayList();
            // Get Records
            while (dbReader.Read())
            {
                ArrayList aryRecord = new ArrayList(nFieldCount);

                for (int i = 0; i < nFieldCount; i++)
                {
                    String strFieldValue = dbReader[i].ToString();
                    aryRecord.Add(strFieldValue);
                }

                RecordSets.m_str2aRecords.Add(aryRecord);
            }
            dbReader.Close();

            return(true);
        }