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
Related Q & A:
- How to store multiple Images in database?Best solution by Stack Overflow
- How to save from DatagridView to Database VB.NET?Best solution by Stack Overflow
- How to update the database in MVC?Best solution by Stack Overflow
- How do I remove an item from my toolbar?Best solution by Yahoo! Answers
- How and why are the wonders of the world selected?Best solution by quora.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.