G
Guest
I need to build a sql string that looks like this:
strSql = "Select * from tbl1 Where x In (123,456,789)"
or
strSql = "Select * from tbl1 Where x In (123,456,789,527,914)"
The numbers represent RecordID's from rows I will select from a
datagridview. I tried storing these values in an arrayList, and even a
string array and tried this:
s1 = New ArrayList
For Each row As DataGridViewRow In SelectedRows
s1.Add(row.Cells("DetailID").Value.ToString)
Next
....
strSql = "Select * from tbl1 Where x In (" & s1 & ")
VS complained until I added s1.ToString, which of course, did not work.
strSql = "Select * from tbl1 Where x In (" & s1.ToString & ")
My alternative is to build a "Where" string
For i As Integer = 0 to s1.Count - 1
str1 += s1(i).ToString & ","
Next
strSql = "Select * from tbl1 Where x In (" & str1 & ")"
This just seems a bit kludgy. I am pretty sure I have dealt with this
before, I just can't remember what object I used.
Any suggestions appreciated.
Thanks,
Rich
strSql = "Select * from tbl1 Where x In (123,456,789)"
or
strSql = "Select * from tbl1 Where x In (123,456,789,527,914)"
The numbers represent RecordID's from rows I will select from a
datagridview. I tried storing these values in an arrayList, and even a
string array and tried this:
s1 = New ArrayList
For Each row As DataGridViewRow In SelectedRows
s1.Add(row.Cells("DetailID").Value.ToString)
Next
....
strSql = "Select * from tbl1 Where x In (" & s1 & ")
VS complained until I added s1.ToString, which of course, did not work.
strSql = "Select * from tbl1 Where x In (" & s1.ToString & ")
My alternative is to build a "Where" string
For i As Integer = 0 to s1.Count - 1
str1 += s1(i).ToString & ","
Next
strSql = "Select * from tbl1 Where x In (" & str1 & ")"
This just seems a bit kludgy. I am pretty sure I have dealt with this
before, I just can't remember what object I used.
Any suggestions appreciated.
Thanks,
Rich