Jump to content

azizalm

Members
  • Posts

    5
  • Joined

  • Last visited

azizalm's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. azizalm

    ADO.Net

    This is the code i Use:Dim the_user As OdbcDataReaderDim myQuery As String = "Select count(*) from users where user_name='" & CStr(username) & "'"Dim myConnection As New OdbcConnection(conn.get_dsn)Dim myCommand As New OdbcCommand(myQuery, myConnection)myConnection.Open()'then the use of this OdbcDataReaderbut i can't run another query know else if i cancel the OdbcCommand and the OdbcDataReaderlike this:the_user.Close()myCommand.Cancel()then i can run another query.and at the end i close the connection:myConnection.Close()My question is like That :How i can run query in a loop of another query without the exception i got.
  2. this cauld is make troubles.Private dbread Private con As OdbcConnection Private comm As OdbcCommand 'function for opening connection and geting query result Function initConnection(ByVal sql As String) ' make sure every thing is closed On Error Resume Next comm = Nothing con.Close() con = Nothing On Error GoTo 0 'open the connection Dim conn As New Connections con = New OdbcConnection(conn.get_dsn()) con.Open() 'execute th sql and assign value to dbread comm = New OdbcCommand(sql, con) dbread = comm.ExecuteReader() Return dbread End Function 'function to close a connection that opened in previos function Function closeConnection() 'after using connection by the initconnection() function the 'closeconnection is the 'function that deal with closeing connection and odbcommand Try comm = Nothing 'set the odbcommand as nothing con.Close() 'close the odbconnections con = Nothing 'set the odbconnection as Nothing Catch ex As Exception End Try End Function '********************************************************************************
  3. azizalm

    ADO.Net

    The function I called to close the connection and destroy is the second one:closeConnection()I made it in class because a mudale in a static and class in publicTherefor i make a class and second is my code is correct because it's make a trouble to me i got the follow:File unKnown or file in use.Cauld you help me?
  4. azizalm

    ADO.Net

    This is the class of the connection (vb.net code as you can see):Imports System.Data.OdbcPublic Class Connections '***************************************************************************** '**************************************************************' ' this is the variables for every connection and data reader. ' ' dberad is as a recordset ' ' con is for creating odbconnection ' ' comm is the odbcommand. ' '**************************************************************' Dim dbread Dim con As OdbcConnection Dim comm As OdbcCommand 'Constructor in this case no need 'function for opening connection and geting query result Function openConnection() ' make sure every thing is closed On Error Resume Next comm = Nothing 'con.Close() 'con = Nothing On Error GoTo 0 'open the connection con = New OdbcConnection("DSN=newBios") con.Open() End Function Function initConnection(ByVal sql As String) 'execute th sql and assign value to dbread comm = New OdbcCommand(sql, con) dbread = comm.ExecuteReader() Return dbread End Function 'function to close a connection that opened in previos function Function closeConnection() 'after using connection by the initconnection() function the 'closeconnection is the 'function that deal with closeing connection and odbcommand Try comm = Nothing 'set the odbcommand as nothing Catch ex As Exception End Try End Function Function destroy() Try con.Close() 'close the odbconnections con = Nothing 'set the odbconnection as Nothing Catch ex As Exception End Try End Function '********************************************************************************End Class
  5. azizalm

    ADO.Net

    I tried to use the oop for the connections, i build a class ia called connections and i make functions in this class to open the connections and one to closein the one that i open the connection a i also send the query that i want to run.sometimes i got exception that the file is alerady in use and that the dsn (unknown filename)If someone can help me i'll be gratefull.
×
×
  • Create New...