Groups | Blog | Home
all groups > vb.net data > january 2005 >

vb.net data : SQL query... is there a better way?


Scott Reynolds
1/18/2005 6:26:11 PM
Hi,

I am using following code to read and generate SQL query based on values
stored in ArrayList. But I am not sure if it is the best way... all
suggestions are
welcome!

Thank you!
Scott


Dim SqlQuery As String
Dim SqlCity As String

If Not Cities.Count = 0 Then
For i As Integer = 0 To Cities.Count - 1
If i = 0 Then
SqlCity = "(City =" + Cities(i) + ")"
Else
SqlCity = SqlCity + " Or (City =" + Cities(i) + ")"
End If
Next
SqlCity = "(" & SqlCity & ")"
End If

SqlQuery = "Select * FROM MyTable WHERE " & SqlCity


lishil NO[at]SPAM online.microsoft.com
1/20/2005 9:55:46 PM



Use "IN" key word when compare city names.

The string should looks like

select * FROM MyTable WHERE City IN ('REDMOND', 'BELLVEUE', 'SEATTLE')

Note: You need quote string value by single quote, (escape single quote by
extra single quote).
If the data type of City is unicode (nchar, nvarchar) put a capital N
before it, it looks like N'REDMOND' .

Lishi, VSData Team


--------------------
[quoted text, click to view]
cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09
.phx.gbl
[quoted text, click to view]
AddThis Social Bookmark Button