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...
Here's my code:
#region "Properties"
public string sql { get; protected set; }
public CommandType cType { get; protected set; }
public List<MySqlParameter> 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<MySqlParameter> 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 > 0)
{
cmd.Parameters.AddRange(args.ToArray());
}
da.SelectCommand = cmd;
da.Fill(dt);
}
if (dt.Rows.Count > 0)
{
return dt;
}
else
{
return null;
}
}
The GetDataTable
function reads in a List<MySqlParameter>
for the parameters needed by the query - this List is defined in the calling code.
At the time where da.Fill(dt);
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:
Here's the stack trace:
[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& affectedRow, Int64& insertedId) +116 MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& 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
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.
Can anyone help me figure out where the parameters are going?
EDIT
In response to Renan's comment:
The parameter names are the same.
The query text (name of stored procedure in this case) is passed into the sql
property when this class is instantiated.
And lastly, the color scheme for my IDE is simply the VS2012 Dark theme