public ReportConfiguration()
 {
     _status = StatusType.Pending;
     MainTable = new DSTable(0,"","");
 }
        private DSTable CreateTable(int schemaId, int objectId)
        {
            DSSchema schemaFinded = null;
            DSTable tableFinded = null;

            schemaFinded = this.Schemas.Find(x => (x.Id == schemaId));
            if (schemaFinded != null)
            {
                tableFinded = schemaFinded.Tables.Find(x => (x.Id == objectId));
            }

            if (tableFinded != null)
            {
                return tableFinded;
            }
            else
            {
                using (SqlConnection connectionCreateTable = new SqlConnection(ConnectionStringRdb))
                {
                    connectionCreateTable.Open();

                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.Append(" Select s.name as SchemaName, ");
                    stringBuilder.Append("        t.name as TableName ");
                    stringBuilder.Append(" from ");
                    stringBuilder.Append(" 	sys.tables t");
                    stringBuilder.Append(" inner join ");
                    stringBuilder.Append(" 	sys.schemas s ");
                    stringBuilder.Append(" on ");
                    stringBuilder.Append(" 	s.schema_id = t.schema_id");
                    stringBuilder.Append(" Where");
                    stringBuilder.Append(" 	t.schema_id = @schema_id");
                    stringBuilder.Append(" and t.object_id = @object_id");

                    SqlCommand commandCreateTable = new SqlCommand(stringBuilder.ToString(), connectionCreateTable);
                    commandCreateTable.Parameters.AddWithValue("schema_id", schemaId);
                    commandCreateTable.Parameters.AddWithValue("object_id", objectId);
                    SqlDataReader readerCreateTable = commandCreateTable.ExecuteReader();
                    if (readerCreateTable.HasRows)
                    {
                        readerCreateTable.Read();
                        DSTable table = new DSTable(objectId, readerCreateTable["TableName"].ToString(), readerCreateTable["SchemaName"].ToString());

                        #region Columns
                        using (SqlConnection connectionColumns = new SqlConnection(ConnectionStringRdb))
                        {
                            connectionColumns.Open();

                            stringBuilder = new StringBuilder();

                            stringBuilder.Append(" Select c.column_id,");
                            stringBuilder.Append("        c.object_id");
                            stringBuilder.Append(" from sys.columns c ");
                            stringBuilder.Append(" Where c.object_id = @object_id");

                            SqlCommand commandColumns = new SqlCommand(stringBuilder.ToString(), connectionColumns);
                            commandColumns.Parameters.AddWithValue("object_id", table.Id);
                            SqlDataReader readerColumns = commandColumns.ExecuteReader();
                            if (readerColumns.HasRows)
                            {
                                table.Columns = new List<DSColumn>();
                                while (readerColumns.Read())
                                {
                                    table.Columns.Add(CreateColumn(columnId: readerColumns.GetInt32(0), objectId: readerColumns.GetInt32(1), schemaId: schemaId));
                                }
                            }
                        }
                        #endregion

                        return table;
                    }
                    else
                    {
                        return null;
                    }
                }
            }
        }