How to fill Combo Box at runtime in VB 6.0 …I’ve used RecordSet object but rec.count of rs obj returns (-1).I hv enough data in the DB

5 pts.
Tags:
ActiveX Data Objects
ADO
ADO Recordset Object
ComboBox
Database connectivity
Database programming
Recordset Object
RunTime
VB 6
Visual Basic
Visual Basic 6
[Private Sub Form_Load() FillCombo End Sub Sub FillCombo() Dim rs As New ADODB.Recordset, SQL As String SQL = "Select Spare_Name from Spare" rs.Open SQL, Conn, adOpenDynamic, adLockOptimistic Dim i As Integer For i = 1 To rs.RecordCount cboSpare.AddItem rs("Spare_Name") rs.MoveNext Next MsgBox "Successss", vbOKOnly End Sub]
ASKED: December 6, 2008  7:49 PM
UPDATED: January 6, 2014  4:05 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

From the <a href=”http://msdn.microsoft.com/en-us/library/ms676701(VS.85).aspx”>RecordCount Property (ADO) Documentation</a>:

<i><b>”… The property returns -1 when ADO cannot determine the number of records or if the provider or cursor type does not support RecordCount.”</b></i>

It could be better to use the <a href=”http://msdn.microsoft.com/en-us/library/ms675787(VS.85).aspx”>EOF Property</a> to check whether you still have records to process, since RecordCount will not always help you with that.

When the data source returns no records, the provider sets both the BOF and EOF properties to True, so you can use that to check if the recordset is really empty.

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • wajantri
    i have combobox with some records in it like id ,code ,villageid  . now wanted select one record ie id=1 and add this same number id=1 to another combo 
    10 pointsBadges:
    report
  • bj2008
    I hope below stmt is simple and work

    if rs.state=1 then rs.close
    rs.Open SQL, Conn, adOpenDynamic, adLockOptimistic
    if Rs.eof=false then
    cboitem.clear
    while rs.eof=false
           cboitem.add(rs(0))
           rs.movenext
    wend

    if rs.state=1 then rs.close
    end if
    10 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following