I'm not familiar with the inner workings of Access, but with many other
database systems the record is not actually deleted.  Rather it is just
marked for deletion so that it can be recovered if needed.  Check the Access
documentation on record deletion and see what it says.

...Glenn

On Thu, Oct 16, 2008 at 3:38 PM, joshturner1967 <[EMAIL PROTECTED]>wrote:

>
> I am having trouble deleting a record from an Access database using
> VB.net
>
> The code compiles and the record that I want is selected but when I
> delete the record it never goes away what am I doing wrong - obviously
> missing a step  I do not get any errors I have 21 records to begin
> with and when I check it after the delete I still have 21 - any ideas?
>
> here is my event code
> Imports System.Data
> Imports System.Data.OleDb
> Imports System.Data.SqlClient
>
> Public Class UserMaint
>
> Private Sub BtnDelete_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles BtnDelete.Click
>
> Dim con As New OleDb.OleDbConnection
>    Dim ds As DataSet = New DataSet
>    Dim reccount As Integer
>
>        con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=C:\TestTheory\Maintapp\Maintapp\mymainttemp.mdb;Persist
> Security Info=False"
>
>        Try
>
>            con.Open()
>
>        Catch OleDbExceptionErr As OleDb.OleDbException
>
>            MessageBox.Show(OleDbExceptionErr.Message)
>
>        End Try
>
>        'If row is selected continue '
>        If Me.DataGridView1.SelectedRows.Count = 1 Then
>
>            Dim dr As DataGridViewRow =
> Me.DataGridView1.SelectedRows.Item(0)
>            MsgBox(dr.Cells(0).Value)
>
>            ' Create the SelectCommand.
>            Dim sql As String = "SELECT * FROM USR"
>
>            ' Create the Delete Statment based upon the user id from
> the selected row.
>            Dim deleteSql = New OleDbCommand("DELETE FROM USR WHERE
> USER_ID = dr.Cells(0).Value")
>
>
>            Try
>                Dim da As OleDbDataAdapter = New OleDbDataAdapter(sql,
> con)
>                da.Fill(ds, "USR")
>
>                Dim dt As DataTable = ds.Tables("USR")
>                da.DeleteCommand = deleteSql
>
>                da.Update(ds, "USR")
>                ds.AcceptChanges()
>
>                Dim scalarCommand As New OleDbCommand("SELECT COUNT(*)
> FROM USR", con)
>
>                USRBindingSource.DataSource = ds.DefaultViewManager
>                MsgBox("After Delete, Number of Employee = " &
> scalarCommand.ExecuteScalar())
>
>
>                DataGridView1.Refresh()
>
>            Catch ex As SqlException
>
>
>                MsgBox("Error: " & ex.ToString())
>
>                ' MsgBox("Error during delete of USR Table for " &
> dr.Cells(0).Value)
>
>
>            End Try
>
>        Else
>            MsgBox("Row not selected")
>
>        End If
>
>    End Sub
> End Class
>
> Thanks Josh
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web 
Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/DotNetDevelopment

You may subscribe to group Feeds using a RSS Feed Reader to stay upto date 
using following url  

<a href="http://feeds.feedburner.com/DotNetDevelopment";> 
http://feeds.feedburner.com/DotNetDevelopment</a>
-~----------~----~----~----~------~----~------~--~---

Reply via email to