title: Must declare the table variable "@".
body: <p>I tried copy data from DB1 to DB2.But I get error : Must declare the table variable "@TableName".</p>
  
  <p>What is wrong this code ?</p>
  
  <p>Function :</p>
  
  <pre><code>  public void TransferData()
  
  
      {
          SqlConnection source = new SqlConnection(strConnectDB1);
          SqlConnection destination = new SqlConnection(strConnectDB2);
  
  
          source.Open();
          destination.Open();
  
          SqlCommand cmd= new SqlCommand("SELECT * FROM @TableName", source);
  
          cmd.Parameters.AddWithValue("@TableName", listbox1.SelectedItem.ToString());
          SqlDataReader reader = cmd.ExecuteReader();
  
  
          SqlBulkCopy bulkData = new SqlBulkCopy(destination);
  
          bulkData.DestinationTableName = listbox1.SelectedItem.ToString();
  
          bulkData.WriteToServer(reader);
  
          .
          .
  
  
      }
  </code></pre>
  
  <p>Button :</p>
  
  <pre><code>    private void button5_Click(object sender, EventArgs e)
      {
          CreateTableName();
  
          TransferData();
  
      }
  </code></pre>