2 Replies - 1813 Views - Last Post: 20 November 2012 - 01:48 PM Rate Topic: -----

#1 kismetgerald  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-November 12

How do I delete database records through a ListView control?

Posted 20 November 2012 - 12:30 AM

Hello and Good morning,

I'm new to this forum and programming in general. I've been working on a small project to store some data in a MySQL database. So far I've been able to follow online tutorials and get help with my code from friends. But now, I want to do something that I can't seem to find any tutorials for. Hence my coming here.

I have data in a MySQL database and I know how to use a SELECT statement to retrieve the records and assign to a DataTable, then populate the ListView control with the contents of the DataTable. Now I'd like help on how to delete those records (individually and collectively by use of buttons). I know the ListView control has a property that allows Checkboxes on each row but I don't know how to use that to select the row(s) I want deleted. Also, I did some reading and found that I can use the .Remove() method to do this, but how do I pass that back to the database?

If anybody knows a tutorial that can help me, please point me in the right direction. Alternatively, if you'll be kind enough to assist me here as well, I'd be grateful.

Is This A Good Question/Topic? 0
  • +

Replies To: How do I delete database records through a ListView control?

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9192
  • View blog
  • Posts: 34,507
  • Joined: 12-June 08

Re: How do I delete database records through a ListView control?

Posted 20 November 2012 - 08:20 AM

The gist is you will be using the 'DELETE' SQL command. I have no idea how your tables are arranged - but there better be a primary key on them. The listview control should be setup in such away the 'DISPLAY MEMBER' is the text you want to show the users and the 'VALUE MEMBER' is this primary you pulled back from the SELECT.

The work flow would be a user selects a row in your list view then clicks the 'delete button' (or which ever event you are using to trigger the delete). The event looks at the list view's "SELECTED ITEM" property... you get the primary key there. Take that, feed it into a sql command object, and 'execute non reader'. Bada bing, bada boom.


Here are some great database tutorials you should look through.


OleDb Basics in VB.Net

A Really Simple Database Create a Database using Access & VB.net Express 2008
Was This Post Helpful? 0
  • +
  • -

#3 kismetgerald  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-November 12

Re: How do I delete database records through a ListView control?

Posted 20 November 2012 - 01:48 PM

Thanks, I will mess around with this later tonight and see if I can get it to work. And yes, I do have a primary key on the table.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1