Visual Basic Development Bookmark and Share   
 Home > Visual Basic General > Delete from a database at a selected index of a listview
 

Delete from a database at a selected index of a listview

Hey all!

Sorry if my questions seem obvious to any/all of you, I'm still learning :)

I am using Visual Basic 2008.
I Have a lilstview with items from an MS Access database loading in to it. I can update, insert and delete all from the database and the listview is updated accordingly. However, I cannnot for the life of me get it to remove a row from the database based on the selected index of the listview!!!

I suppose I could use a DataGridView but then I would need to add a datasource wouldn't I?

Any ideas?

Regards,

Rich.

P.S Do you think it would be better to add a datasource to my project and use a listbox instead of the listview?
Rickz2K  11 hours 43 minutes ago
Hey all!

Sorry if my questions seem obvious to any/all of you, I'm still learning :)

That's what makes MSDN great; consider a public forum to be a collaborative effort and your questions (from beginner to advanced) to be active contributions where others with the same or similar issues may find it helpful in the future.

I am using Visual Basic 2008.
I Have a lilstview with items from an MS Access database loading in to it. I can update, insert and delete all from the database and the listview is updated accordingly. However, I cannnot for the life of me get it to remove a row from the database based on the selected index of the listview!!!

Your database doesn't actually have rows; a database contains tables and columns, and Tables have rows. I suspect the problem here is that Query Results also have Rows, and a row in a query result does not necessarily correspond to a row in a Table; so you fill a RecordSet or DataTable object from a query in code, then fill a listview from that, then try to direct-modify a table based on the listview, and you've made spaghetti soup.

What you want to do is explicitly identify an individual row in a table to be updated; that means you have to take the data from the listview (and know which column in the listview goes with which database Table and which Column in that Table) and then construct and execute an SQL UPDATE or INSERT statement that will target those data elements.

There are easier ways to accomplish this depending on what you're using (OLE, ODBC, ADO) to get hooks into your Access Database. If you can clear this up, somebody may be able to supply code.

It never hurts to try. In a worst case scenario, you'll learn from it.
Andrew B. Painter  10 hours 0 minutes ago
Hey all!

Sorry if my questions seem obvious to any/all of you, I'm still learning :)

I am using Visual Basic 2008.
I Have a lilstview with items from an MS Access database loading in to it. I can update, insert and delete all from the database and the listview is updated accordingly. However, I cannnot for the life of me get it to remove a row from the database based on the selected index of the listview!!!

I suppose I could use a DataGridView but then I would need to add a datasource wouldn't I?

Any ideas?

Regards,

Rich.

P.S Do you think it would be better to add a datasource to my project and use a listbox instead of the listview?
can you post your code here please?
Don't judge me, just Upgrade me. Thanks!
Malange  9 hours 24 minutes ago

You can use google to search for other answers

Custom Search

More Threads

• Authenication and member of group
• How to call another form
• Error in OLE DB in VB.NET data source wizard.
• RESX Question
• Problem with Video Capture
• VS .net 2005 network deployment
• Lost Again - BindingSource and PictureBox Control
• runtime error '3146'
• Create Help Pages
• CheckedListBox