IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SSIS Discussion :

Script c# ecrire dans une output colonne si test vrai [2012]


Sujet :

SSIS

  1. #1
    Membre éclairé
    Homme Profil pro
    Consultant en Business Intelligence
    Inscrit en
    Novembre 2013
    Messages
    226
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Consultant en Business Intelligence
    Secteur : Industrie

    Informations forums :
    Inscription : Novembre 2013
    Messages : 226
    Par défaut Script c# ecrire dans une output colonne si test vrai
    Bonjour,

    J'ai mis en place un script qui test les guillemets sur toutes les colonnes et pour chaque ligne.

    Afin de terminer mon test, je souhaite mettre une colonne en output du script afin de mettre 1 si je trouve au moins 1 guillemet sur la ligne testée sinon 0.

    Le soucis c'est que je n'arrive pas à ecrire le resultat de mon test dans une colonne.

    Le script en entier :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    // This script adjusts the value of all string fields
    using System;
    using System.Data;
    using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
    using Microsoft.SqlServer.Dts.Runtime.Wrapper;
    using System.Windows.Forms;
    using System.Reflection;
     
     
    [Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
     
    public class ScriptMain : UserComponent
    {
        int var1;
     
        //  Method that will be started for each record in you dataflow 
        public override void Input0_ProcessInputRow(Input0Buffer Row)
        {
            // Use Reflection to loop through all the properties of Row: 
            // Example: 
            // Row.Field1 (String) 
            // Row.Field1_IsNull (Boolean) 
            // Row.Field2 (String) 
            // Row.Field2_IsNull (Boolean)
     
     
     
            foreach (PropertyInfo p in Row.GetType().GetProperties())
            {
                // Do something for all string properties: Row.Field1, Row.Field2, etc. 
     
                try //check error when null
                {
                    if (object.ReferenceEquals(p.PropertyType, typeof(string)))
                    {
                        // Use a method to set the value of each String type property 
                        // Make sure the length of the new value not exceed the column size 
                        p.SetValue(Row, DoSomething(p.GetValue(Row, null).ToString()), null);
                        //ecriture dans une colonne output
                        Row.checkcolumn.Equals(var1);
                     }
     
                }
                catch (NullReferenceException e)
                {
     
                }
     
            }
        }
     
        // New function that you can adjust to suit your needs 
        public string DoSomething(string ValueOfProperty)
        {
     
                if (ValueOfProperty.Contains("\""))
                {
                    Variables.var1 = 1;
     
                }
                else
                {
                    Variables.var1 = 0;
                }
     
                return ValueOfProperty;
        }
     
    }

    Merci par avance.

  2. #2
    Membre éclairé
    Homme Profil pro
    Consultant en Business Intelligence
    Inscrit en
    Novembre 2013
    Messages
    226
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Consultant en Business Intelligence
    Secteur : Industrie

    Informations forums :
    Inscription : Novembre 2013
    Messages : 226
    Par défaut
    J'ai résolu mon problème

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    // This script adjusts the value of all string fields
    using System;
    using System.Data;
    using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
    using Microsoft.SqlServer.Dts.Runtime.Wrapper;
    using System.Reflection;            // Added
     
    [Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
     
    public class ScriptMain : UserComponent
    {
        //  Method that will be started for each record in you dataflow 
        public override void Input0_ProcessInputRow(Input0Buffer Row)
        {
            // Use Reflection to loop through all the properties of Row: 
            // Example: 
            // Row.Field1 (String) 
            // Row.Field1_IsNull (Boolean) 
            // Row.Field2 (String) 
            // Row.Field2_IsNull (Boolean) 
            foreach (PropertyInfo p in Row.GetType().GetProperties())
            {
                // Do something for all string properties: Row.Field1, Row.Field2, etc. 
                if (object.ReferenceEquals(p.PropertyType, typeof(string)))
                {
                    // Use a method to set the value of each String type property 
                    // Make sure the length of the new value doesnt exceed the column size
     
                    if (Row.checkCol == 0)
                    {
                        Row.checkCol = DoSomething(p.GetValue(Row, null).ToString());
                    }
     
                    //p.SetValue(Row, DoSomething(p.GetValue(Row, null).ToString()), null);
                }
            }
        }
     
        // New function that you can adjust to suit your needs 
        public int DoSomething(string ValueOfProperty)
        {
            // Uppercase the value 
            int test =3;
            if (ValueOfProperty.Contains("\""))
            { test = 1; }
            else { test = 0; }
            return test;
        }
     
    }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [AC-2003] ecrire dans une table nligne sur une même colonne
    Par cedill23 dans le forum VBA Access
    Réponses: 2
    Dernier message: 03/07/2009, 19h57
  2. Réponses: 0
    Dernier message: 26/02/2008, 19h23
  3. Réponses: 4
    Dernier message: 15/04/2005, 16h25
  4. Résultats dans une même colonne.
    Par souellet dans le forum Langage SQL
    Réponses: 6
    Dernier message: 10/03/2004, 20h51
  5. Resultat requete dans une seule colonne
    Par mathieu--g dans le forum Sybase
    Réponses: 2
    Dernier message: 08/07/2003, 14h42

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo