我试图执行,目前工作在phpMyAdmin的查询,但使用MySqlAdapter在.NET中执行时,它不工作。这是SQL语句。
I'm trying to execute a query that currently works in phpMyAdmin but it does not working when executing it in .NET using the MySqlAdapter. This is the Sql statement.
SELECT @rownum := @rownum +1 rownum, t . *
FROM (
SELECT @rownum :=0
) r, (
SELECT DISTINCT
TYPE FROM `node`
WHERE TYPE NOT IN ('ad', 'chatroom')
)t
这是使用@rownum到数量从我内心的标量查询返回的每个不同行。但是,如果我在.NET中使用它的假设@rownum是一个参数,并抛出一个异常,因为我没有定义它。
It is using the @rownum to number each distinct row that is returned from my inner scalar query. But if I use it in .NET it's assuming that the @rownum is a parameter and throwing an exception because I didn't define it.
using (var sqlConnection = new MySqlConnection(SOURCE_CONNECTION))
{
sqlConnection.Open();
MySqlDataAdapter sqlAdapter = new MySqlDataAdapter(SqlStatement, sqlConnection);
DataTable table = new DataTable();
sqlAdapter.Fill(table);
sqlConnection.Close();
return table;
}
任何想法,我怎么能解决这个问题?或者我可能的方式来获得行号?
Any ideas for how I could get around this problem? Or possible ways for me to get a line number?
推荐答案
我发现这个blog,它告诉,与从不版本的.NET连接器必须添加
I found this blog, which tells, that with never versions of .net Connector you have to add
;Allow User Variables=True
在连接字符串。 比较我太问题How我可以使用MySQL用户定义的变量一个.NET的MySqlCommand?
to the connection string. Compare my SO question How can I use a MySql User Defined Variable in a .NET MySqlCommand?
相关推荐
最新文章