title: C# - How to send Insert with @Parameters to Database Connection Class
body: <p>Having a bit of an issue getting my insert to work properly. When I run the insert all within the same method, it works flawlessly... however when I try to send the Insert statement to my new Connection class (which I will have handle all database requests), I am getting the following error. </p>
  
  <p>Note: I am using C# and Microsoft SQL Server.</p>
  
  <pre><code>System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@CollectionGroupID".
  </code></pre>
  
  <p>I believe I am not sending the parameters over, however I am not sure of the best way to do this. </p>
  
  <p>Here's my AddGame method:</p>
  
  <pre><code>public static void AddGame(int gameId)
      {
  
          string statement = "INSERT INTO Collection (CollectionGroupID, SharedID, UserID, GameID, Owned, Favorited, WishList, DeletedIndicator, AddUser, AddDate, ModUser, ModDate) VALUES (@CollectionGroupID, @SharedID, @UserID, @GameID, @Owned, @Favorited, @WishList, @DeletedIndicator, @AddUser, @AddDate, @ModUser, @ModDate)";
  
          using (SqlCommand cmd = new SqlCommand())
          {
  
              cmd.Parameters.AddWithValue("@CollectionGroupID", "0");
              cmd.Parameters.AddWithValue("@SharedID", "0");
              cmd.Parameters.AddWithValue("@UserID", "0"); 
              cmd.Parameters.AddWithValue("@GameID", gameId);
              cmd.Parameters.AddWithValue("@Owned", "Y");
              cmd.Parameters.AddWithValue("@Favorited", "N");
              cmd.Parameters.AddWithValue("@WishList", "N");
              cmd.Parameters.AddWithValue("@DeletedIndicator", "N");
              cmd.Parameters.AddWithValue("@AddUser", "test/admin");
              cmd.Parameters.AddWithValue("@AddDate", DateTime.Now);
              cmd.Parameters.AddWithValue("@ModUser", "test/admin");
              cmd.Parameters.AddWithValue("@ModDate", DateTime.Now);
  
  
              Connection.Open();
              Connection.Statement(statement);
              Connection.Close();
  
  
          }
      }
  </code></pre>
  
  <p>And here is my Statement method in my Connection class</p>
  
  <pre><code>public static void Statement(string sql)
      {
          Console.WriteLine("Attempting to submit data to the database...");
  
          try
          {
              SqlCommand cmd = new SqlCommand(sql, conn);
              cmd.ExecuteNonQuery();
          }
          catch (SqlException e)
          {
              Console.WriteLine(e);
          }
  
      }
  </code></pre>
  
  <p>I feel like perhaps I am overlooking a simple solution. Any help appreciated!</p>
  
  <p>-Travis W.</p>