gpt4 book ai didi

MySQL 连接器 : parameters not being added

转载 作者:可可西里 更新时间:2023-11-01 08:38:24 27 4
gpt4 key购买 nike

查看我的 MySQL 查询日志,我发现我的参数没有被添加。这是我的代码:

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();
}

查看查询日志,我看到了这个:

SELECT COUNT(*) AS totalViews
FROM pr_postreleaseviewslog AS prvl
WHERE prvl.dateCreated BETWEEN (@startDate) AND (@endDate) AND prvl.postreleaseID IN (1,2)

我在无数项目中使用过 MySQL .NET 连接器(我实际上有一个基类负责打开这些连接,并通过事务关闭它们等)。但是,我接手了这个应用程序,现在就在这里。

感谢您的帮助!

最佳答案

像这样尝试。

mySqlCommand.Parameters.Add("@CustomerID", SqlDbType.NChar, 5);
mySqlCommand.Parameters["@CustomerID"].Value = "T1COM";

关于MySQL 连接器 : parameters not being added,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1411819/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com