|
-
Mar 25th, 2004, 12:14 PM
#1
.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:
Private Sub Form_Load()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=SQLOLEDB.1;....." '<-- Full connection string
cn.Open
Set rs = New ADODB.Recordset
With rs
.ActiveConnection = cn
.CursorLocation = adUseServer
.CursorType = adOpenForwardOnly
.LockType = adLockReadOnly
.Source = "SELECT DISTINCT Titles, Authors From Books"
.Open
End With
Do While Not rs.EOF
cboTitles.AddItem rs!Titles & ""
cboAuthors.AddItem rs!Authors & ""
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
-
Mar 25th, 2004, 02:19 PM
#2
Frenzied Member
I have the same setup. I am working on that currently and will post my code unless someone else beats me to it
-
Mar 25th, 2004, 02:29 PM
#3
Lively Member
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
-
Mar 25th, 2004, 08:29 PM
#4
Sleep mode
-
Mar 25th, 2004, 09:12 PM
#5
Frenzied Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|