How to select specific data from listbox?

How to DELETE and UPDATE access database after remove selected item from VB listbox?

  • I trying to make a code to Delete and Update Access 2007 database after remove a selected item from a listbox in VB 2008. [using "Remove" button that i create] pervious i already make a button to View data from database and Remove from listbox. but i don't know how to delete and update in database. i have 3 fields ID, Name and Age in database. Imports System.Data.OleDb Public Class Form1 Dim cn As OleDbConnection Dim cmd As OleDbCommand Dim cmd2 As OleDbCommand Dim dr As OleDbDataReader Dim str As String Private Sub btmView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btmView.Click cn = New OleDbConnection("Provider=Microsoft.Jet.… Source=Database11.mdb") cn.Open() cmd = New OleDbCommand("select * from Test1", cn) dr = cmd.ExecuteReader While dr.Read() ListBox1.Items.Add(dr(0) & vbTab & dr(1) & vbTab & dr(2)) End While dr.Close() cn.Close() End Sub Private Sub btmSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btmSave.Click cn = New OleDbConnection("Provider=Microsoft.Jet.… Source=Database11.mdb") cn.Open() str = "insert into Test1 (Name, Age) values ('" & txtName.Text & "','" & CInt(txtAge.Text) & "')" cmd = New OleDbCommand(str, cn) cmd.ExecuteNonQuery() MessageBox.Show("Saved") cn.Close() End Sub End Class hope someone can help me..

  • Answer:

    Delete is DELETE FROM tablename WHERE fieldname = 'value' http://www.w3schools.com/sql/sql_delete.asp Update is UPDATE tablename set fieldname = 'value' http://www.w3schools.com/sql/sql_update.asp (No ticks around the value if it's numeric, ## as the delimiters if it's time/date.)

Prince at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.