MySQL Connector: parameters not being added
Posted
by LookitsPuck
on Stack Overflow
See other posts from Stack Overflow
or by LookitsPuck
Published on 2009-09-11T16:01:54Z
Indexed on
2010/04/16
5:03 UTC
Read the original article
Hit count: 309
mysql
|mysql-connector
Hey all!
Looking at my query log for MySQL, I see my parameters aren't being added. Here's my code:
MySqlConnection conn = new MySqlConnection(ApplicationVariables.ConnectionString());
MySqlCommand com = new MySqlCommand();
try
{
conn.Open();
com.Connection = conn;
com.CommandText = String.Format(@"SELECT COUNT(*) AS totalViews
FROM pr_postreleaseviewslog AS prvl
WHERE prvl.dateCreated BETWEEN (@startDate) AND (@endDate) AND prvl.postreleaseID IN ({0})"
, ids);
com.CommandType = CommandType.Text;
com.Parameters.Add(new MySqlParameter("@startDate", thisCampaign.Startdate));
com.Parameters.Add(new MySqlParameter("@endDate", endDate));
numViews = Convert.ToInt32(com.ExecuteScalar());
}
catch (Exception ex)
{
}
finally
{
conn.Dispose();
com.Dispose();
}
Looking at the query log, I see this:
SELECT COUNT(*) AS totalViews
FROM pr_postreleaseviewslog AS prvl
WHERE prvl.dateCreated BETWEEN (@startDate) AND (@endDate) AND prvl.postreleaseID IN (1,2)
I've used the MySQL .NET connector on countless projects (I actually have a base class that takes care of opening these connections, and closing them with transactions, etc.). However, I took over this application, and here I am now.
Thanks for the help!
© Stack Overflow or respective owner