Results 1 to 3 of 3

Thread: VB6 MSSQL Windows Authentication & Select Count in TextBox

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    5

    VB6 MSSQL Windows Authentication & Select Count in TextBox

    All,

    I am looking for an example of the windows authenticated connection to an MSSQL DB and a select count statement in a textbox in my form.

    I have this connection string:

    Code:
    Dim SQLCon As ADODB.Connection
    
     
    Set SQLCon = New ADODB.Connection
    
    With SQLCon 
    Provider=SQLOLEDB.1;Integrated Security=True;Initial Catalog=MY DATABASE;Data Source=MY SERVER;Persyst Security Info=False;Command Properties='Command Time Out=45'" 
    End With
    Can I simply just paste this into my form_onload? Also how to I reference this connection when I then go to add my SQL query to textboxes etc?

    Does anyone have any example code they would be willing to share or take the time to explain this to me.

    Any replice will be much appreciated.

    Thanks,

    Ben.
    Last edited by whitelockben; Feb 12th, 2012 at 01:39 PM.

  2. #2
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Question Re: VB6 MSSQL Windows Authentication & Select Count in TextBox

    Can I simply just paste this into my form_onload? Also how to I reference this connection when I then go to add my SQL query to textboxes etc?

    Does anyone have any example code they would be willing to share or take the time to explain this to me.

    Any replice will be much appreciated.
    i am not sure what you want to achieve .but try the following way .

    Code:
    Dim SQLCon As ADODB.Connection
    dim rs as New adodb.recordset
    
     
    Set SQLCon = New ADODB.Connection
    
    With SQLCon 
     Provider=SQLOLEDB.1;Integrated Security=True;Initial Catalog=MY DATABASE;Data Source=MY SERVER;Persyst Security Info=False;Command Properties='Command Time Out=45'" 
    .open
    End With
    
    Now
    rs.open sqlcon,con,adopendynamic,adlockoptimistic
    
    if rs.state=adstateopen then
       
      ---if you want to refere  database fields and pull into the textboxes .just do the following way
       txtname.text=rs.fields("0")
       Txtaddress.text=rs.fields("1")
    end if
    Last edited by firoz.raj; Feb 13th, 2012 at 05:27 AM.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    5

    Re: VB6 MSSQL Windows Authentication & Select Count in TextBox

    Quote Originally Posted by firoz.raj View Post
    i am not sure what you want to achieve .but try the following way .

    Code:
    Dim SQLCon As ADODB.Connection
    dim rs as New adodb.recordset
    
     
    Set SQLCon = New ADODB.Connection
    
    With SQLCon 
     Provider=SQLOLEDB.1;Integrated Security=True;Initial Catalog=MY DATABASE;Data Source=MY SERVER;Persyst Security Info=False;Command Properties='Command Time Out=45'" 
    .open
    End With
    
    Now
    rs.open sqlcon,con,adopendynamic,adlockoptimistic
    
    if rs.state=adstateopen then
       
      ---if you want to refere  database fields and pull into the textboxes .just do the following way
       txtname.text=rs.fields("0")
       Txtaddress.text=rs.fields("1")
    end if
    Thank you for the reply! What I want to do is add some select counts to textboxes. Do you know how I would do this please? Can I just use the datasource field of the textbox once I have declared my connection?

    Ben

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width