MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old February 26th, 2005, 12:16 AM
Neoblaze Neoblaze is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 1 Neoblaze User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 m 31 sec
Reputation Power: 0
Unhappy SQL Query help needed

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

Reply With Quote
  #2  
Old February 27th, 2005, 03:20 AM
gertcuppens's Avatar
gertcuppens gertcuppens is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 118 gertcuppens User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 28 m
Reputation Power: 5
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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > SQL Query help needed


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway