|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
i am using the following Visual Basic 6 code to connect to connect to MYSQL server 4.1.10
and retrive the table contents. My problem is that i am getting the error: You have an error in SQL syntax; check your manual that corresponds to to your MySQL Server verion for the right syntax to use near 'WHERE Settinng = 'Default' ORDER BY ContID DESC' at Line 1 .. though i cannot see anything wrong with the syntax ... can someone point out what i have missed. Public Sub LoadContactInfo() 'load contact information into lvRecNames Const sMOD_NAME As String = "frmHome.LoadContactInfo" Dim Item As ListItem Dim SQL As String Dim strPhone As String Dim strSetting As String strSetting = "Default" SQL = "SELECT TOP 22 ContID, Setting, ShownName FROM Contacts " SQL = "WHERE Setting = '" & strSetting & "' " SQL = SQL & "ORDER BY ContID DESC" MsgBar "Opening Database", True Screen.MousePointer = vbHourglass Set m = New MySQLVB.cMysql With m m.user = "root" m.Password = "mypass" m.host = "localhost" m.DB = "blah" m.Port = 3306 'Optional, 3306 is default m.real_connect Set rsList = m.real_query(SQL, Len(SQL)) With rsList If (.RecordCount > 0) Then .MoveFirst While Not .EOF If (Not IsNull(!ContID)) Then Set Item = lvRecNames.ListItems.Add(, "ID" & !ContID, !ShownName) strPhone = GetPhoneNum(!ContID) Item.SubItems(1) = strPhone End If .MoveNext Wend End If End With If (g_blnAltColors = True) Then AltLVBackground lvRecNames, picGrdClr End If End With rsList.Close Set rsList = Nothing m = Nothing Exit Sub End Sub |
|
#2
|
||||
|
||||
|
I have no knowledge whatsoever of Visual Basic, I'm
more a Java amateur. But when I see the following code : Code:
SQL = "SELECT TOP 22 ContID, Setting, ShownName FROM Contacts " SQL = "WHERE Setting = '" & strSetting & "' " SQL = SQL & "ORDER BY ContID DESC" I wonder what VB does whit this. In the last line, you write : SQL = SQL & "ORDER BY" So, I assume you are concatenating. But the second line is only : SQL = "WHERE Setting = '" & strSetting & "' " Doesn't this mean that you're giving your variable SQL a new value ? If I'm correct, your SQL statement should be something like WHERE Setting = 'something' ORDER BY CONTID DESC Last edited by gertcuppens : February 27th, 2005 at 03:21 AM. Reason: correcting some errors |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > SQL Query help needed |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|