ASP.NET / MySQL
MySQL LIMIT Statement Created by select SUM().
The above code is using a data reader. If you don't close connections between the two queries in the code behind, you get this error:
There is already an open DataReader associated with this Connection which must be closed first.
MySQL does not support MARS, so you cannot use "MultipleActiveResultSets=True." The choice is to close the connection after the ExecuteReader() command, or code another solution using data sets or execute scalar instead of using the MySQLDataReader.
Here is an example of the same code, but with an Execute Scalar instead of the MySQLDataReader. The benefit of this is that everything is done with one open connection instead of two. ExecuteScalar seems to be the preferred method when only a single value needs to be returned.
Tags: asp.net 3.5, Visual Basic, VB, MySQL 5.1, MySQL .net connector, Limit X, Limit ?, Limit with a variable, execute scalar, executescalar, execute scalar without a stored procedure.
Using ExecuteScalar Method without Stored Procedures