2017-09-22 3 views
0

Initialement j'avais commandtext défini dans ma tâche de script ssis C# qui comptait le nombre de lignes de la table A. Maintenant, j'ai besoin d'ajouter deux commandtext qui compte les lignes de la table b et C respectivement car j'ai besoin d'inclure la sortie de cette requête dans mon email personnalisé.Comment avoir du texte de commande multiple dans SSIS C#

try 
     { 
      dbConnection.Open(); 

      if (dbConnection.State == ConnectionState.Open) 
      { 
       OleDbCommand dbCommand = dbConnection.CreateCommand(); 
       dbCommand.CommandType = CommandType.Text; 
       dbCommand.CommandText = "select count(*) as Total_Source from [dbo].A"; 
       dbCommand.CommandText = "select count(*) as Total_Destination from [dbo].B"; 
       dbCommand.CommandText = "select count(*) as Total_Blank from [dbo].C where ColumnA = ''"; 
       OleDbDataReader dbReader = dbCommand.ExecuteReader(); 

       if (dbReader.HasRows) 
        dtResults.Load(dbReader); 

       string theSum = dtResults.Rows[0]["Total_Source"].ToString(); 
       string theSum1 = dtResults.Rows[0]["Total_Destination"].ToString(); 
       //string theSum2 = dtResults.Rows[0]["Count_Blank"].ToString(); 

je crois que je dois définir le texte de commande pour la table B et C (ce qui est incorrect dans le script ci-dessus), mais je ne connais pas comment faire.

Appréciez toute aide!

Répondre

0

Je ne l'ai pas essayé, mais je pense que si CommandText est une propriété string, vous l'écrasez sur chaque phrase que vous utilisez l'opérateur =.

Vous pouvez essayer ceci:

//... 

OleDbCommand dbCommand = dbConnection.CreateCommand(); 
dbCommand.CommandType = CommandType.Text; 
var sb = new System.Text.StringBuilder(); 
sb.Append("select count(*) as Total_Source from [dbo].A;"); // Notice semicolon at the end of the string. 
sb.Append("select count(*) as Total_Destination from [dbo].B;"); 
sb.Append("select count(*) as Total_Blank from [dbo].C where ColumnA = '';"); 
dbCommand.CommandText = sb.ToString(); 
OleDbDataReader dbReader = dbCommand.ExecuteReader(); 

//... 
+0

J'ai essayé append plus tôt sans succès ... –

+0

Je pense que la valeur de retour est remplacée par le résultat de la requête précédente, vous devez séparer chaque requête et exécuter séparément – LONG

0

Conserver les comptes dans les variables et retourner ceux qui sont en sélection - faire votre instruction SQL:

DECLARE @total_Source AS INT; 
DECLARE @total_Destination AS INT; 
DECLARE @total_Blank AS INT; 
SELECT @total_Source=Count(*) FROM [dbo].A; 
SELECT @total_Destination=Count(*) FROM [dbo].B; 
SELECT @total_Blank=Count(*) FROM [dbo].C WHERE ColumnA = ''"; 
SELECT @total_Source AS Total_Source, @total_Destination AS Total_Destination, @total_Blank AS Total_Blank 
+0

Egalement ce que @ Eliasib13 a dit, vous écrasez votre CommandText. Je n'ai même pas remarqué ça. –