title: DataAdapter Fill gets no parameters from the Command object
body: <p>I'm trying to fill a data table from my DataAdapter, but the database keeps reporting back that no parameters were specified for the query...</p>
  
  <p>Here's my code:</p>
  
  <pre><code>    #region "Properties"
      public string sql { get; protected set; }
      public CommandType cType { get; protected set; }
      public List&lt;MySqlParameter&gt; args { get; protected set; }
      public string rValue { get; protected set; }
  
      private MySqlConnection conn;
  
      private string server = "127.0.0.1";
      private string database = "stman";
      private string user = "root";
      private string password = "root";
      #endregion
  
      #region "Constructor Logic"
          public Database(string CommandText, CommandType CommandType, List&lt;MySqlParameter&gt; Parameters, string ReturnParameter = "")
          {
              buildConnection();
  
              sql = CommandText;
              cType = CommandType;
              args = Parameters;
              rValue = ReturnParameter;
          }
  
          public Database(string CommandText, CommandType CommandType)
          {
              buildConnection();
  
              sql = CommandText;
              cType = CommandType;
          }
  
          private void buildConnection()
          {
              StringBuilder sb = new StringBuilder();
              sb.Append(String.Format("data source={0}; initial catalog={1}; user id={2}; password={3};", server, database, user, password));
  
              conn = new MySqlConnection(sb.ToString());
          }
      #endregion
  
      public DataTable GetDataTable()
      {
          DataTable dt = new DataTable();
          MySqlDataAdapter da = new MySqlDataAdapter();
  
          using (MySqlCommand cmd = new MySqlCommand(sql, conn))
          {
              if (args.Count &gt; 0)
              {
                  cmd.Parameters.AddRange(args.ToArray());
              }
  
              da.SelectCommand = cmd;
              da.Fill(dt);
          }
  
          if (dt.Rows.Count &gt; 0)
          {
              return dt;
          }
          else
          {
              return null;
          }
      }
  </code></pre>
  
  <p>The <code>GetDataTable</code> function reads in a <code>List&lt;MySqlParameter&gt;</code> for the parameters needed by the query - this List is defined in the calling code.</p>
  
  <p>At the time where <code>da.Fill(dt);</code> is hit, the MySqlCommand does have the correct parameters for the query in question, and, judging by the stack trace (see below), it appears that the attempt to get the data from mysql does go through and that it is actually mysql that's sending back this error:</p>
  
  <p><img src="https://i.stack.imgur.com/0IzCA.png" alt="Incorrect number of arguments for PROCEDURE stman.Users_SelectByEmailAndPassword; expected 2, got 0"></p>
  
  <p>Here's the stack trace:</p>
  
  <blockquote>
    <p>[MySqlException (0x80004005): Incorrect number of arguments for PROCEDURE stman.Users_SelectByEmailAndPassword; expected 2, got 0]
       MySql.Data.MySqlClient.MySqlStream.ReadPacket() +383
       MySql.Data.MySqlClient.NativeDriver.GetResult(Int32&amp; affectedRow, Int64&amp; insertedId) +116
       MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32&amp; affectedRows, Int64&amp; insertedId) +54
       MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force) +145
       MySql.Data.MySqlClient.MySqlDataReader.NextResult() +1258
       MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) +2364
       MySql.Data.MySqlClient.MySqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +41
       System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +10
       System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +140
       System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) +160
       System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) +108
       stman.Database.GetDataTable() in d:\Development\stman\stman\App_Code\Database.cs:85
       stman.LoginContext.DoLogin() in d:\Development\stman\stman\App_Code\LoginContext.cs:45
       stman.Login.processLogin() in d:\Development\stman\stman\Login.aspx.cs:40
       stman.Login.btnLogin_Click(Object sender, EventArgs e) in d:\Development\stman\stman\Login.aspx.cs:32
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9553594
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724</p>
  </blockquote>
  
  <p>I've been filling DataTables like this for years, and this is the first time I've come across this error. I don't know why it's happening or how to fix it.</p>
  
  <p>Can anyone help me figure out where the parameters are going?</p>
  
  <p><strong>EDIT</strong><br>
  In response to Renan's comment:  </p>
  
  <p>The parameter names are the same.<br>
  The query text (name of stored procedure in this case) is passed into the <code>sql</code> property when this class is instantiated.<br>
  And lastly, the color scheme for my IDE is simply the VS2012 Dark theme</p>