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,124 of 10,840   
   Paul Anderson to Paul Anderson   
   Re: Sharing an object created at run-tim   
   21 Jun 06 11:38:40   
   
   From: patech@magma.ca   
      
   I figured out an answer.  Basically it's just my unfamiliarity with   
   objects coming through.  Just in case other people have the same   
   question though:   
      
   I should have instantiated the object at the form level with no   
   parameters, then set the paramters at the button level as follows:   
      
   My bad.   
      
   ===============================================   
      
   Public Class Form1   
      
   dim strOLEDbConnString as string   
   dim dbConn as New OLeDBConnection()   
      
   Private Sub BtnLogin_Click(ByVal sender As System.Object, ByVal e As   
   System.EventArgs) Handles BtnLogin.Click   
      
   strOLEDbConnString  = _   
   "Provider=MSDAORA; _   
   DataSource=my_db; _   
   User ID=" & txtUserid.Text & ";Password=" & txtPassword.Text   
      
   dbConn.connectionstring = 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 wrote:   
   > 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