Exemplo n.º 1
0
    /*-----------------------------------------------------------------------------
    | Function GetDataTable: Return DataTable
    |  -----------------------------------------------------------------------------*/
    public static DataTable GetDataTable(string strSQL, string strConn)
    {
        DataTable Returndt = null;
        DataTable dt       = new DataTable();

        ClassFunction_Eform.ConnectDatabase Conn;

        if (strConn == "")
        {
            Conn = new ClassFunction_Eform.ConnectDatabase(System.Configuration.ConfigurationManager.ConnectionStrings["Myconnect"].ConnectionString);
        }
        else
        {
            Conn = new ClassFunction_Eform.ConnectDatabase(System.Configuration.ConfigurationManager.ConnectionStrings[strConn].ConnectionString);
        }

        try
        {
            Conn.OpenDatabase();
            dt = Conn.GetData(strSQL);

            if ((dt == null))
            {
                dt = null;
            }
            else
            {
                if (dt.Rows.Count == 0)
                {
                    Returndt = null;
                }
                else
                {
                    Returndt = dt;
                }
            }
        }
        catch (Exception ex)
        {
            Conn.RollbackDatabase();
            throw ex;
        }
        finally
        {
            Conn.CloseDatabase();
        }
        return(Returndt);
    }