Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello there I have been pulling out my hair to try and figure out why my code will not close the MySQL datareader. I need to be able to return the information by using a function

VB
Public Shared Function SQLDATAREAD() As MySqlDataReader
       Dim SQL_CMD As New MySqlCommand
       With SQL_CMD
           .CommandText = "select Names, Boys, Girls from Gender"
           .Connection = MYSQL_DBCONNECTION
           .CommandType = CommandType.Text
       End With
       SQLDATAREAD = SQL_CMD.ExecuteReader
       Return SQLDATAREAD()
       SQLDATAREAD.Close()
   End Function


I have a open connection which works fine but every time the code errors saying that there is a open databasereader which must be closed first but this is the only reader that I am using?

Please help I would like to know where I have went wrong or what I have forgot to add, any help would be greatly appreciated.
Posted
Comments
Wombaticus 8-Aug-14 8:38am    
Your .Close method is being called after the return statement - so in fact is not being called at all
Richard MacCutchan 8-Aug-14 8:39am    
You have a Return statement before the call to Close.

Just posting an answer to get this out of the Unanswered questions list.
 
Share this answer
 
Use only dataset and mysqladapter ...this is so easy to retrieve a data from mysql database...
example:

VB
Public ds As Dataset
Public da As MysqlAdapter

ds = New Dataset
da = New MysqlAdapter("here should be the sql query to retrieve data", MysqlConnectionString)
da.Fill(ds, "here should be the table name of query")
MsgBox("Success")


You can create you custom function by including my code block to any named function you want just remember > Return value will be "ds" that means Dataset,,,,


Enjoy Programming,,, :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900