Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 8th, 2006, 02:04 AM
Registered User
 
Join Date: Sep 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Add&Remove rows from DB using listbox

Dear readers,

I have a simple Access database with a table with names. I am an
old V6 user, beginning to use VB2005

I created a listbox that lists all the records in my database table,
using the Databindings.

I created an ADD button, to add new records, and update my database with the .update command. Working.

I cannot find sample code to select a record from my list box, and
Delete the record from my database.

Also if I want to select a record from the listbox, change the contents, and update my database.

It is propably the same using a datagridview control.
I would appreciate it if someone could help me with some sample
code to add,edit & delete from a table using the listbox or datagridview controls, using VB2005

Very much appreciated.
 
Old September 8th, 2006, 09:56 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

If you are using an edit command column in a datagrid, you have an onDeleteCommand attribute of your datagrid and you can also add a delete button to your edit command column and then, when the delete button is pressed just write some logic to delete the currently selected value in the text box.

"The one language all programmers understand is profanity."
 
Old September 11th, 2006, 05:58 AM
Registered User
 
Join Date: Sep 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear dparsons,

Thanks for the reply, but it is the "just write some logic" part that I need
to get right. I am using a LISTBOX, and after I selected a record in my
listbox, I click my Delete button to remove it. I am not sure how to tell
my Table adapter, that record no 3 in my list box need to be deleted.

Please help.

 
Old September 11th, 2006, 06:24 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You have to loop through your list box and in your routine you need something like this:

Dim lb As ListBox = CType(e.Item.Cells(x).Controls(x), ListBox)
Dim li as ListItem

For each li in lb
   if li.selected [do something]
next

"The one language all programmers understand is profanity."





Similar Threads
Thread Thread Starter Forum Replies Last Post
add & Remove frm Listbox hotshot_21 ASP.NET 1.0 and 1.1 Basics 1 June 21st, 2007 05:26 PM
Alternating Colors in ListBox rows nkrust ASP.NET 1.0 and 1.1 Basics 2 January 10th, 2007 03:27 PM
Alternating Colors in ListBox rows nkrust ASP.NET 1.0 and 1.1 Professional 1 January 10th, 2007 09:47 AM
asp boxlist add/remove lip13 Classic ASP Basics 1 December 10th, 2004 06:47 PM
remove rows to Sheet2 (cells in columnA filled RED alienscript Excel VBA 1 December 2nd, 2003 12:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.