home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.visual.basic      MS Visual Basic discussions, NOT dot-net      10,840 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 10,123 of 10,840   
   Paul Anderson to All   
   Sharing an object created at run-time   
   21 Jun 06 09:41:44   
   
   From: patech@magma.ca   
      
   I have a form in which I want to connect to an OLEdb datasource with a   
   logon button.  I also want the user to be able to disconnect with a   
   logoff button.   
      
   The connection string relies on input from two input boxes, txtUserid   
   and txtPassword which are filled in before the login button is clicked.   
      
   My problem is that because the connection string is being created   
   "dynamically" in this way, it can't be defined at the form level since   
   the boxes won't be filled in when the form loads.  Therefore the   
   connection needs to be defined in BTNLogin_Click (see below).   
      
   Unfortunately this means it's private and so BtnLogout_Click can't   
   reference it (i.e.  the skeleton code below wouldn't work).   
      
   Can anyone give me any hints about how I might create and open a   
   connection dynamically in one routine, then close it later in another?   
      
   Not sure if this is a newbie question or not but I don't seem to be able   
   to find the answer.   
      
   Thanks.   
      
      
   =============================================   
   Public Class Form1   
      
   Private Sub BtnLogin_Click(ByVal sender As System.Object, ByVal e As   
   System.EventArgs) Handles BtnLogin.Click   
   Dim strOLEDbConnString As String = "Provider=MSDAORA;Data   
   Source=my_db;User ID=" & txtUserid.Text & ";     Password=" &   
   txtPassword.Text   
      Dim dbConn As New OleDbConnection(strOLEDbConnString)   
      dbConn.Open()   
      
   End Sub   
      
   Private Sub BtnLogout_Click(ByVal sender As System.Object, ByVal e As   
   System.EventArgs) Handles BtnLogout.Click   
      
     dbConn.Close()   
      
   End Sub   
      
   End Class   
      
   =================================================   
      
   Paul Anderson   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca