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 3 1775
Like this?
strSql = "Select * from tbl1 Where x In (" & String.Join(",",
s1.ToArray(Type.GetType("System.String"))) & ")
Regards
Matthias
"Rich" <Ri**@discussions.microsoft.comschrieb im Newsbeitrag
news:B4**********************************@microsof t.com...
>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
Well here is one other option I remembered that makes it so I can use a
string array
strSql = "Select * from tbl1 Where x In (" & String.Join(",", s1) & ")"
This doesn't seem any less kludgy than using a straight string object
though, because I have to resize the string array, I have to add a counter
var to the for each loop, and I have to use String.Join in the sql statement.
But -- it is another option.
"Rich" wrote:
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
Yes. Exactly. This is what I came up with also, so I guess this is the
consensus. And the reason I need some kind of collection object is because
in the rest of this particular process I have to loop through the object
after I build the sql string and retrieve rows. With the string array I can
use For Each Next.
"Matthias Vastring" wrote:
Like this?
strSql = "Select * from tbl1 Where x In (" & String.Join(",",
s1.ToArray(Type.GetType("System.String"))) & ")
Regards
Matthias
"Rich" <Ri**@discussions.microsoft.comschrieb im Newsbeitrag
news:B4**********************************@microsof t.com...
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: ian justice |
last post by:
Before i post actual code, as i need a speedyish reply.
Can i first ask if anyone knows off the top of their head, if there is
a likely obvious cause to the following problem.
For the moment i've...
|
by: serge |
last post by:
Using "SELECT * " is a bad practice even
when using a VIEW instead of a table?
I have some stored procedures that are
identical with the difference of one statement
in the WHERE clause. If I...
|
by: DC Gringo |
last post by:
I have an image control (that pulls an image off an ESRI map server):
<ASP:IMAGE ID="imgZonedCountry" RUNAT="server"></ASP:IMAGE>
In the code behind I am setting the ImageURL to a String value...
|
by: DC Gringo |
last post by:
I am having a bear of a time with setting a URL query string as a text value
in a dropdownlist and Server.URLEncode does not seem to do its job.
theFullLink = theLinkPrefix &...
|
by: VB Newbie |
last post by:
I am creating a user control containing a combobox using VB.NET(2003)
I want to add 2 public properties "DataSource" and "Items" like the
"System.Windows.Forms.ComboBox"
here is my code, but it...
|
by: Arne |
last post by:
A lot of Firefox users I know, says they have problems with validation
where the ampersand sign has to be written as & to be valid. I don't
have Firefox my self and don't wont to install it only...
|
by: divya |
last post by:
Hi,
I have a table tblbwday with 2 fields Name and Birthday.I have written
this script for displaying evryday names of the people on that day.
<%
set objConn...
|
by: pagoto123 |
last post by:
select * from table where director = '" & Director.text & "'
i want to display me all results that start with the director that the user will enter........ please i need the command help me...
|
by: Medvedev |
last post by:
i see serveral source codes , and i found they almost only use "new"
and "delete" keywords to make they object.
Why should i do that , and as i know the object is going to be destroy
by itself at...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |