Hi Everyone.
I am totally new here and this is my first post..
I have tried many place, since i could get any solution.
I have no choice then posting here.
basically, i have one delete form, where i will load the firstname from a table in access(hardcode) to listbox.
then when a user choose the first name, from list box and click delete.
the entire row related to the first name should be delete.
Please guide me. thank you
The code, i wrote so far..
Imports System.Data
Imports System.Data.OleDb
Public Class Delete
Dim inc, MaxRows As Integer
Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim da As New OleDb.OleDbDataAdapter
Dim sql As String
Private Sub Delete_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
System.Environment.CurrentDirectory.ToString() & "\DataBase.mdb"
con.Open()
MsgBox("A Connection to the Database is now open")
sql = "SELECT * From Contacts"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "DataBase")
Me.lstNames.DataSource = ds.Tables("DataBase")
'Me.ddlName.ValueMember = "ID"
Me.lstNames.DisplayMember = "FirstName"
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
'lstNames.Items.Remove(lstNames.SelectedItem)
Dim cb As New OleDbCommandBuilder(da)
ds.Tables("DataBase").Rows(inc).Delete()
MaxRows = MaxRows - 1
inc = 0
da.Update(ds, "DataBase")
MessageBox.Show("Contact Deleted Succesfully")
End Sub
Private Sub NavRecords()
lstNames.Text = ds.Tables
End Sub
End Class