SqlCommand Parameters not working
<p>Task:</p>

<p>Replace certain variables within an sql statement with the requisite data.</p>

<p>Issue:</p>

<p>The variables are not being replaced</p>

<p>C# code:</p>

<pre><code>SqlCommand cmd = new SqlCommand(@"
     select 
                 1 [GL], 
                 (
                     select 
                             isnull(COUNT(*), 0)
                         from 
                             @DataDB..APSetup
                 ) [AP],
                 (
                     select 
                             isnull(COUNT(*), 0)
                         from
                             @DataDB..ARSetup
                 ) [AR],
                 (
                     select 
                             isnull(COUNT(*), 0)
                         from 
                             @DataDB..CASetup
                 ) [CA],
                 case 
                     when (
                          select 
                                  isnull(COUNT(*), 0) 
                              from
                                  @DataDB..SalesTax
                          ) &gt; 0 
                         then 1 else 0
                 end [TX], 
                 (
                     select 
                             isnull(COUNT(*), 0)
                         from
                             @DataDB..INSetup
                 ) [IN], 
                 (
                     select
                             isnull(COUNT(*), 0)
                         from 
                             @DataDB..POSetup
                 ) [PO],
                 (
                     select
                             isnull(COUNT(*), 0)
                         from 
                             @DataDB..SOSetup
                 ) [SO], 
                 (
                     select 
                             isnull(COUNT(*), 0)
                         from
                             @DataDB..RQSetup
                 ) [RQ],
                 (
                    select 
                             COUNT(*)
                        from 
                             @DataDB..pcsetup 
                        Where 
                             Setupid = 'PC' AND PERNBR &lt;&gt; ''
                 ) [PJ] 
    from 
          @DataDB..glsetup");

    cmd.Parameters.AddWithValue("@DataDB", CurrentBranch.AppDB);
    AppConnection.InitialCatalog = CurrentBranch.AppDB;
    Modules.AddRange(SqlQueries.DataQuery2(cmd, AppConnection.ConnectionString)); 
</code></pre>

<p>Sql Query:</p>

<pre><code>select 1 [GL], (select isnull(COUNT(*),0) from @DataDB..APSetup) [AP], (select isnull(COUNT(*),0) from @DataDB..ARSetup) [AR], (select isnull(COUNT(*),0) from @DataDB..CASetup) [CA], case when (select isnull(COUNT(*),0) from @DataDB..SalesTax) &gt; 0 then 1 else 0 end [TX], (select isnull(COUNT(*),0) from @DataDB..INSetup) [IN], (select isnull(COUNT(*),0) from @DataDB..POSetup) [PO], (select isnull(COUNT(*),0) from @DataDB..SOSetup) [SO], (select isnull(COUNT(*),0) from @DataDB..RQSetup) [RQ],  (select COUNT(*) from @DataDB..pcsetup Where Setupid = 'PC' AND PERNBR &lt;&gt; '') [PJ] from @DataDB..glsetup
</code></pre>

<p>Question:</p>

<p>Why does the variable replacement not work?</p>

<p>Additional Information:</p>

<p>The issue is not the query, when I manually replace the @DataDB with its intended value it works fine.</p>

<p>The issue is the C# SqlCommand.Parameters.AddWithValue();</p>
