|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
sql query select
I want to select an item from a listbox, this query works fine and all fields of CLASS are present in the listbox. My problem is that I want to select a CLASS and get all the students from the selected class into another listbox. I get an error on data3.refresh, I think my error lies with that my datafield cant be refreshed. Here is the code
- Private Sub lstClasses_DblClick() Dim SQL As String Dim amount As Integer Dim help As String help = lstclasses.Text SQL = "Select STAMBOEKNR from STUDENTS Where CLASS Like " & help & " Order by 1" Data3.RecordSource = SQL Data3.Refresh Data3.Recordset.MoveFirst amount = Data3.Recordset.RecordCount For i = 1 To aantal lststamboek.AddItem (Text6.Text) Data3.Recordset.Movenext Next i - thanks! |
|
#2
|
||||
|
||||
|
I see one problem with your sql query. Help is a string and needs single quotes:
SQL = "Select STAMBOEKNR from STUDENTS Where CLASS Like '" & help & "' Order by 1" |
|
#3
|
|||
|
|||
|
still doesnt work :-(
|
|
#4
|
||||
|
||||
|
assuming you are using SQL Server.
since you are using the LIKE command you need to use the wildcard character with the statement, like this Code:
For SQL Server SQL = "SELECT stamboeknr FROM students WHERE class LIKE '%" & help & "%' ORDER BY 1" Code:
For Access SQL = "SELECT stamboeknr FROM students WHERE class LIKE '*" & help & "*' ORDER BY 1" Depending on where you place the wildcard character in the statement determines what it searches for. Code:
Returns everything where the fieldName BEGINS WITH the value passed SELECT * FROM tableName WHERE fieldName LIKE '" & value & "%' Code:
Returns everything where the fieldName ENDS WITH the value passed SELECT * FROM tableName WHERE fieldName LIKE '%" & value & "' Code:
Returns everything where the fieldName CONTAINS the value passed SELECT * FROM tableName WHERE fieldName LIKE '%" & value & "%' |
|
#5
|
|||
|
|||
|
It should always be the correct value, because its selected from a database. So I dont think the wildcard character is needed.
|
|
#6
|
|||
|
|||
|
I get all the items from STAMBOEKNR in my lisbox and not those whom I selected with the query, I can't find the problem. I use microsoft access database, no sql server.
Last edited by jodeman : January 20th, 2004 at 04:21 PM. |
|
#7
|
|||
|
|||
|
i found it, it was a little mistake :-s. I used two names for the same string, help and hulp.
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > sql query select |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|