Comma Problem string manipulation

WillBoss

Member
Joined
May 31, 2006
Messages
8
Programming Experience
Beginner
Hi
I have simple problem that is causing me to get a bad headache.
here is my sinppet of code that is causing the problems:
VB.NET:
         '***********trying to loop through list boxes Aghaaa!!!!
        Dim loopzip_code As String = Nothing
        Dim loopstore_code As String = Nothing
        Dim i As Integer
        Dim bflag As Boolean = False
        'loopzip_code = "0"
        'loopstore_code = "0"
        For i = 0 To DDPostCode.Items.Count() - 1
            If DDPostCode.Items(i).Selected Then
                If bflag = False Then
                    loopzip_code = loopzip_code & "'" & DDPostCode.Items(i).Value & "'" & ","
                    bflag = True
                Else
                    loopzip_code = loopzip_code & "'" & DDPostCode.Items(i).Value & "'"
                End If
            End If

The problem is that I am trying to get rid of the comma at the end of my sql query. Above I tried a Boolean but that didnt work as this is only putting a comma after the first select item in my list box. Thats great if I select only two items. My sql query at the moment reads:
VB.NET:
SQL Query=select email_address from subscriber_list where zip_code in ('45675','23456''44444''73653');
As you can see the comma is only after the first entry. The way I had it previously I had a comma after them all but it was also after the last entry which wa no good. either. This is wrecking my head.

Thanks in advance
Will
 
VB.NET:
         Dim loopzip_code As String = Nothing
        Dim loopstore_code As String = Nothing
        'loopzip_code = "0"
        'loopstore_code = "0"
        For i as integer = 0 To DDPostCode.Items.Count() - 1
            If DDPostCode.Items(i).Selected Then
                    loopzip_code &= "'" & DDPostCode.Items(i).Value & "'"
                If not i = DDPostCode.items.Count - 1 Then
                    loopzip_code &= ","
                End If
            End If
        Next

Basically it checks if i is the last item in DDPostCode, if it isnt it will put a comma
 
Another problem now. I am getting a SQL error when I run the app:

There was a problem sending the email. #42000You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

I display the sql syntax to the screen to see what the problem is but it looks fine to me. Here it is:

VB.NET:
select email_address from subscriber_list where zip_code in ('45675','23456','44444','73653');

Thanks
 
Back
Top