View Single Post
 
Old 05-07-2015, 09:12 PM
VPL VPL is offline
Newcomer
 
Join Date: Apr 2015
Posts: 1
Default Delete record using code

I am new to vb.net and started learning it for the last two weeks.

I created one table in Access with following fields

a. Request ID
b. Person Name
c. Request Date
d. Customer Type (New or already existing)
e. Customer Code
f. Customer Name

I tried to delete a record with following code
Code:
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles Me.Load
        dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
        dbSource = "Data Source = E:\sample-status\ggoe.mdb"
        con.ConnectionString = dbProvider & dbSource
        con.Open()
        sql = "SELECT * FROM samplerequest"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "ggoe")
        'con.Close()
        MaxRows = ds.Tables("ggoe").Rows.Count
End Sub
==========================================

Private Sub Delete_Click(sender As Object, e As EventArgs) Handles Delete.Click
        inc = 0
        For inc = 0 To MaxRows
        	If Val(RequestNo.Text) = inc Then
        inc = inc - 1
       	 Dim cb As New OleDb.OleDbCommandBuilder(da)
If MessageBox.Show("Do you really want to Delete this Record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then
        MsgBox("Operation Cancelled")
        Exit Sub
        End If
        ds.Tables("ggoe").Rows(inc).Delete()
       	 MaxRows = MaxRows - 1
        da.Update(ds, "ggoe")
       	 Exit Sub
        End If
        Next inc
    End Sub
==================================
I got error message "One of the parameter is missing"

Please help me to correct this error.

Last edited by Flyguy; 05-08-2015 at 02:20 AM.
Reply With Quote