Click here to Skip to main content
15,887,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to this framework site i am working on vb.net and my codes as above please some one help me.
its gives me errors

What I have tried:

VB.NET
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click

    Rss = New ADODB.Recordset

    Rss.Open("DELETE FROM Employee WHERE Serial_No = '" txtSNo.Text.Trim "'", CON)

    
    Rss.Delete("Serial_No")
    Rss.Delete("Employee_Name")
    Rss.Delete("F_Name")
    Rss.Delete("Designation")
    Rss.Delete("Dept_Name")


    MsgBox("Record Deleted Successfully", MsgBoxStyle.Information, strprojectname)

    Rss.Close()
End Sub
Posted
Updated 19-Dec-16 2:34am
v5
Comments
Michael_Davies 19-Dec-16 7:07am    
What is the error message, which line.

As far as I can remember when using a recordset to delete you move the recordset to the record you want to delete then invoke recordset.Delete.

So the Rss.Open would be a SELECT that located a single record, or you open the recordset without any SQL and move to the record you want to delete using Filter (filter is a lot slower than using SELECT)
Saadbinata 19-Dec-16 7:50am    
suggest me something to solve this problem. Please
Saadbinata 19-Dec-16 8:34am    
Rss.Delete("Serial_No")

InvalidcastException was unhandled
(Make sure the source type convertible to the destination type)
shows at the end bracket

1 solution

As per my comment, you need to move the recordset to the record you want to delete, assuming that Serial_No is a unique identifier;

VB
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click

    Rss = New ADODB.Recordset

    Rss.Open("SELECT * FROM Employee WHERE Serial_No = '" txtSNo.Text.Trim "'", CON, CursorTypeEnum.adOpenDynamic, LockTypeEnum.adLockOptimistic)

    If Rss.BOF = True And Rss.EOF = True Then
       MsgBox("Record Not Found")
    Else
       Rss.Delete

       MsgBox("Record Deleted Successfully", MsgBoxStyle.Information, strprojectname)
    End If

    Rss.Close()
End Sub
 
Share this answer
 
v2

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