|
-
May 4th, 2005, 03:57 AM
#1
Thread Starter
Lively Member
no duplicate value in the comboBox(Resolved)
hi,
I want to avoid the duplicate course tittle in the comboBox when I load the form. It is allow to add new course tittle if there is not in the combobox. I have try to search from the examples but none of them are relevant. Please help.
Private Sub Form_Load()
rs.Open "select * from Course ", con, adOpenDynamic, adLockPessimistic
while Not rs.EOF
cbProg.AddItem (rs("CourseTittle"))
rs.MoveNext
Wend
end sub
Last edited by vivian2u; May 6th, 2005 at 09:53 AM.
-
May 4th, 2005, 04:03 AM
#2
Re: no duplicate value in the comboBox
I don't think its possible through SQL, so you might have to do something like this:
VB Code:
Private Sub Form_Load()
rs.Open "select * from Course ", con, adOpenDynamic, adLockPessimistic
While Not rs.EOF
[b]For i = 0 To cbProg.ListCount - 1
If Not (rs("CourseTitle") = cbProg.List(i)) Then[/b]
cbProg.AddItem (rs("CourseTittle"))
rs.MoveNext
[b]End If
Next i[/b]
Wend
End Sub
Hope that helps,
Phreak
Visual Studio 6, Visual Studio.NET 2005, MASM
-
May 4th, 2005, 07:08 AM
#3
Re: no duplicate value in the comboBox
Why not: SELECT DISTINCT CourseTitle FROM Course
-
May 6th, 2005, 09:51 AM
#4
Thread Starter
Lively Member
Re: no duplicate value in the comboBox
Hi,
SELECT DISTINCT CourseTitle FROM Course is a good idea and problem solved. Thanks
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
|