Click here to Skip to main content
15,905,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


I want to Delete record using Button control. There is no error occurred in compile but record still exist in database my coding is below. Give Solution for this


cn = New OleDbConnection("Provider= Microsoft.Jet.Oledb.4.0;Data source =" & Server.MapPath("DEO.mdb"))
        cn.Open()
        cmd = New OleDbCommand("select FileName from Paripatra", cn)

        Dr = cmd.ExecuteReader


        If Dr.HasRows = True Then

            Dr.Read()

            Dim Delrec As String

            Delrec = "DELETE from Paripatra where FileName = '" & Session.Item("strfile") & Session.Item("Extent") & "'"

            'Delrec = " Update from Paripatra"
            Delrec = cmd.CommandText
        End If

        Dr.Close()
        cmd.ExecuteNonQuery()

    End Sub
End Class
Posted
Updated 13-Mar-13 4:12am
v3
Comments
joshrduncan2012 13-Mar-13 9:59am    
You need to refresh your table after the deletion takes place, otherwise the record will stay in there.
Md Jamaluddin Saiyed 13-Mar-13 10:08am    
I have refreshed it but record not deleted
CHill60 13-Mar-13 10:19am    
You've used Delrec = cmd.CommandText so Delrec now contains "select FileName from Paripatra"
Did you mean to use cmd.CommandText = Delrec??
[no name] 13-Mar-13 10:25am    
Nicely spotted. This is likely the answer.
Md Jamaluddin Saiyed 13-Mar-13 10:37am    
Thank you Very much sir ! Now I got my mistake !! I have solved it !! Thanks again !! I could not found my mistake

1 solution

See comments above.
OP had used Delrec = cmd.CommandText instead of
cmd.CommandText = Delrec
so the previous select command was actually being executed instead of the delete.
 
Share this answer
 
Comments
Maciej Los 13-Mar-13 16:15pm    
+5!
CHill60 13-Mar-13 18:08pm    
Many thanks ML

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900