I have a project that is CLS-Compliant except one variable declaration which is confusing me how to correct.
I have a class called MySQL, summed up it looks like:
public class mysql
implements idisposable
private connection as new mysqlconnection
private command as new mysqlcommand
<CLSCompliant(false)> public reader as mysqldatareader
public sub new(byval query as string)
if connection.state = connectionstate.open then
connection.connectionstring = my.settings.connectionstring
connection.open()
command.connection = connection
command.commandtext = query
end sub
public sub parameters(byval name as string, byval value as string)
command.parameters.addwithvalue(name, value)
end sub
public sub retrieve()
reader = command.executereader()
end sub
public sub send()
command.executenonquery()
end sub
public sub close()
if me.command.connection.state = connectionstate.open then me.command.connection.close
if me.connection.state = connectionstate.open then me.connection.close
me.dispose()
end sub
#region "IDisposable support"
private disposedvalue as boolean
protected overridable sub dispose(disposing as boolean)
if not me.disposedbalue then
if disposing then
#dispose maaged state
end if
connection.dispose()
command.dispose()
reader = nothing
end if
me.disposedvalue = true
end sub
public sub dispose() implement idisposable.dispose
dispose(true)
gc.suppressfinalize(me)
end sub
#end region
end class
usage:
dim sql as new MySQL("SELECT * FROM TABLE WHERE NAME = ?Name")
sql.parameters("?Name", me.textboxusername.text)
call sql.retrieve()
while sql.reader.read
text = sql.reader.getstring(sql.readergetordinal("User_Name")
end while
call sql.close()
Public reader as MySQLDataReader is not CLS-Compliant and I am not sure how to correct the issue. I have upgraded to the latest mysql data connector version. I am wondering if I should make it a private variable and read the results threw a function?
I apologize for miss-capitalization, miss-spelling, etc. in the following code snippet, I typed it while viewing it from a remote desktop connection.
Try this code sir for declaring mysqlcommand .
Public query As String, cmd As MySqlCommand, reader As MySqlDataReader
Public SQLConnection As MySqlConnection = New MySqlConnection