473,396 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Loop Through / Delete From ListBox

I've created 2 listboxes with buttons that transfer items between the
two. The idea is that one of the listboxes will have a collection of
items to be deleted from the database. I haven't found any
documentation on how to loop through the listbox to build a query
string. I'm guessing it will look a little like [pseudo-code]:

Dim strSQL as string = "DELETE FROM tbl x,y,z WHERE "
For Each item in listbox2

i = i + 1

strSQL += "Name= '" & listbox2.item & "'"

If # of items in listbox2 > 1 Then
strSQL += " AND "
Else
strSQL += ";"
End If

Next

Could anyone help me with the syntax for this listbox. I'm trying to
read up on it but am having no luck.

Thanks in advance.

Nov 19 '05 #1
2 1323
I would use the IN statement that takes a list of id values.

string deleteIdList = "";
foreach(ListItem item in listBox.Items){
deleteIdList += item.Value + ",";
}
deleteIdList = deleteIdList.TrimEnd(',');
string deleteSql = String.Format("Delete from tbl where it in({0})",
deleteIdList):

Nov 19 '05 #2
I'm using VB.net

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: flupke | last post by:
Hi, i'm having trouble with deleting elements from a list in a for loop ============== test program ============== el = print "**** Start ****" print "List = %s " % el index = 0 for line...
1
by: Graham Swindon | last post by:
What is the best way to delete multiple records selected from a list box?
7
by: yue | last post by:
Hi, How do I loop through listbox items? Thanks, yue
1
by: Tim | last post by:
Hi, I'm very new to .NET and am programming in C#. I have a web application where i have two list boxes. Its kind of like a shopping card where you can add items from one 'locations' list box to...
4
by: Ryan Ternier | last post by:
Thanks for the previous help guys! I got my list box issue working, but now i'm trying to loop through all the items in my page. I want to find each listbox, once I do i strip the ID down to...
2
by: jim Bob | last post by:
Hi, I have a form with a list box that shows the contents of a table and managed to create an add record button with the wizard. (DoCmd.GoToRecord , , acNewRec) Now i want to make a delete...
0
by: lanmou | last post by:
hi, I have a listbox whose datasource property is set.i would like to delete the item from the listbox after the records of that item are deleted from the database.the selecteditem.clear or refresh...
1
by: shredder249 | last post by:
Hi, I have a list box (called genredelete) and i'm trying to write a procedure to delete all the selected items in the list box. The code i have written to do this is as follows: Dim...
0
by: dudeja.rajat | last post by:
On Sat, Aug 30, 2008 at 2:32 PM, Fredrik Lundh <fredrik@pythonware.comwrote: Fredrik, Thanks so much. That worked. Following this, I can now see that my combo2 has no previous elements and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...
0
agi2029
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.