CSDataBase.cDataBase.loadDataTable C# (CSharp) Method

loadDataTable() public method

public loadDataTable ( bool showWindowCancel, bool raiseProgressEvent, bool showModal, string sqlstmt, DataTable &dt, System.Data.Common.DbDataReader &dr, string function, string module, string title ) : bool
showWindowCancel bool
raiseProgressEvent bool
showModal bool
sqlstmt string
dt System.Data.DataTable
dr System.Data.Common.DbDataReader
function string
module string
title string
return bool
        public bool loadDataTable(bool showWindowCancel,
                                     bool raiseProgressEvent,
                                     bool showModal,
                                     string sqlstmt,
                                     out DataTable dt,
                                     out DbDataReader dr,
                                     string function,
                                     string module,
                                     string title)
        {
            DbDataReader ors;
            if (openRsEx(showWindowCancel,
                            raiseProgressEvent,
                            showModal,
                            sqlstmt,
                            out ors,
                            function,
                            module,
                            title))
            {
                dr = ors;
                dt = new DataTable();
                dt.Load(ors);
                return true;
            }
            else
            {
                dt = null;
                dr = null;
                return false;
            }
        }

Usage Example

Example #1
0
        private bool pGetData(
            ref DataTable vRows,
            ref DataTable rs,
            cReportConnect connect,
            bool createIndexVector,
            List<object[]> recordsets)
        {
            String strConnect = "";
            bool saveInReport = false;
            CSDataBase.cDataBase cn = null;
            object[] varRs = null;
            DataTable rsAux = null;
            DbDataReader dr = null;

            // if we get an string connection
            //
            if (m_launchInfo.getStrConnect().Trim() != "")
            {
                strConnect = m_launchInfo.getStrConnect();
            }
            // if m_launchInfo.getStrConnect() is empty we will use
            // the connection of the connect object
            // 
            else
            {
                strConnect = connect.getStrConnect();
                saveInReport = true;
            }
            if (!getReportDisconnected())
            {
                if (strConnect.Trim() == "")
                {
                    cWindow.msgWarning("The connection settings were not defined."
                                        + "Both the LaunchInfo and the Connect object have their "
                                        + "strConnect property empty. Whitout this connection string "
                                        + "it will be imposible to open the connection to the database.",
                                        "CSReportEditor");
                    return false;
                }

                cn = new cDataBase(m_databaseEngine);

                if (m_isForWeb)
                {
                    cn.setSilent(true);
                }
                if (connect.getCommandTimeout() > 0)
                {
                    cn.setCommandTimeout(connect.getCommandTimeout());
                }
                if (connect.getConnectionTimeout() > 0)
                {
                    cn.setConnectionTimeout(connect.getConnectionTimeout());
                }

                // open the connection
                //
                if (!cn.initDb("", "", "", "", strConnect))
                {
                    if (!resumeDBAccessMissing(strConnect, saveInReport, cn))
                    {
                        return false;
                    }
                }

                // we need to prepare the first sentence
                //
                String sqlstmt = "";

                // if it was a select
                //
                if (m_launchInfo.getSqlstmt().Trim() != "")
                {
                    sqlstmt = m_launchInfo.getSqlstmt();
                }
                else
                {
                    if (connect.getDataSourceType() == csDataSourceType.CDDTPROCEDURE)
                    {
                        sqlstmt = "exec [" + connect.getDataSource() + "] " + connect.getSqlParameters();
                    }
                    else if (connect.getDataSourceType() == csDataSourceType.CSDTTABLE)
                    {
                        sqlstmt = "select * from [" + connect.getDataSource() + "]";
                    }
                    else
                    {
                        sqlstmt = connect.getDataSource();
                    }
                }

                // open the recordset
                //
                cn.setOpenRsExDescript(m_descripUser);

                if (!cn.loadDataTable(true,
                                        false,
                                        false,
                                        sqlstmt,
                                        out rs,
                                        out dr,
                                        "GetData",
                                        C_MODULE,
                                        ""))
                {
                    return false;
                }

                if (rs.Rows.Count == 0)
                {
                    vRows = null;
                    if (createIndexVector)
                    {
                        m_vRowsIndex = new int[0];
                        m_lastRowIndex = -1;
                    }
                }
                else
                {
                    vRows = rs;
                    if (createIndexVector)
                    {
                        m_vRowsIndex = new int[vRows.Rows.Count];
                        m_lastRowIndex = m_vRowsIndex.Length - 1;
                        int k = 0;
                        for (k = 0; k < m_vRowsIndex.Length; k++)
                        {
                            m_vRowsIndex[k] = k;
                        }
                    }
                }

                varRs = new object[2];
                varRs[0] = rs;
                varRs[1] = connect.getDataSource();
                recordsets.Add(varRs);

                // we need to load every recordset from every data source
                // in the recordset collection (this code suport multiples
                // recordset in the same reader)
                //
                while (!dr.IsClosed && dr.NextResult())
                {
                    rsAux = new DataTable();
                    rsAux.Load(dr);
                    
                    varRs = new object[2];
                    varRs[0] = rsAux;
                    varRs[1] = connect.getDataSource();
                    recordsets.Add(varRs);

                    // TODO: check if this works
                    //
                    // we add an empty element to m_collRows to avoid
                    // index of bounds exception
                    //
                    G.redimPreserve(ref m_collRows, m_collRows.Length + 1);
                }

                cn.closeDb();
            }
            else
            {
                vRows = null;
                if (createIndexVector)
                {
                    m_vRowsIndex = new int[0];
                    m_lastRowIndex = -1;
                }
            }
            if (m_rows != null)
            {
                m_recordCount = m_vRowsIndex.Length;
            }
            else
            {
                m_recordCount = 0;
            }
            m_iRow = 0;
            m_idxGroupHeader = -1;
            m_idxGroupFooter = -1;

            return true;
        }