Results 1 to 5 of 5

Thread: .NET Recordset???

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    .NET Recordset???

    This code works fine in VB6 to populate a few combo boxes from a couple of fields in a db. What is the equivalent of this in .NET?
    VB Code:
    1. Private Sub Form_Load()
    2. Dim cn As ADODB.Connection
    3. Dim rs As ADODB.Recordset
    4.  
    5.     Set cn = New ADODB.Connection
    6.     cn.ConnectionString = "Provider=SQLOLEDB.1;....." '<-- Full connection string
    7.     cn.Open
    8.    
    9.     Set rs = New ADODB.Recordset
    10.     With rs
    11.         .ActiveConnection = cn
    12.         .CursorLocation = adUseServer
    13.         .CursorType = adOpenForwardOnly
    14.         .LockType = adLockReadOnly
    15.         .Source = "SELECT DISTINCT Titles, Authors From Books"
    16.         .Open
    17.     End With
    18.    
    19.     Do While Not rs.EOF
    20.         cboTitles.AddItem rs!Titles & ""
    21.         cboAuthors.AddItem rs!Authors & ""
    22.         rs.MoveNext
    23.     Loop
    24.    
    25.     rs.Close
    26.     Set rs = Nothing
    27.    
    28.     cn.Close
    29.     Set cn = Nothing
    30. End Sub

  2. #2
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    I have the same setup. I am working on that currently and will post my code unless someone else beats me to it

  3. #3
    Lively Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    71
    I have not tested this but it should get you going.

    Dim rdrRead as SqlDataReader
    Dim cn as New SqlConnection("SQLOLEDB.1;....." )
    Dim cmd as New SqlCommand ("SELECT DISTINCT Titles, Authors From Books",cn)

    Dim strAuthors as string

    cn.open
    rdrRead = cmd.ExecuteReader()

    While rdrPeople.Read()
    strAuthors = rdrRead.GetString(1)
    cboAuthors.Items.Add(strAuthors)
    End While
    cn.Close

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by thephantom
    I have the same setup. I am working on that currently and will post my code unless someone else beats me to it
    I thought you're ADO.NET guy...

  5. #5
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    Originally posted by Pirate
    I thought you're ADO.NET guy...
    shoot not!!! I'm still a newbie around here ado.net is something I learn on the side for now cause my boss wants me to use ado

    One day though......

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