My requirement is to delete a selected row in the datagrid from SQL server. If no row is selected then nothing should happen.

Below is my code

Private Sub BT_Remove_Click()
On Error GoTo ErDsc:
Dim MyConn As ADODB.Connection
Dim MyRecSet1 As New ADODB.Recordset
Set MyConn = New ADODB.Connection
MyConn.ConnectionString = "Provider=SQLOLEDB;Data Source=TGSSRV-08;Initial Catalog=RMG;User Id=RMG;Password=Thinksoft;Trusted_Connection=no"

    If AddProfile.DataGrid2.SelBookmarks.Count = 0 Then
        MsgBox ("Please select the profile that you want to delete"), vbOKOnly, "Alert"
        Exit Sub
    End If

But when the code is executed I am gettign error "RowSet not available"

Dont know the reason. Kindly help me.

7 Years
Discussion Span
Last Post by divakar.it

No. I didn't select any row in the data grid and no record in the data grid. If you say the issue is no recordset in datagrid, then wats the solution if no recordset is there in datagrid and user trying to click the remove button.

Please post some sample code snippets


Populating grid from recordset. But if user click remove button when the grid is empty then how to manage the error?


I presume you are populating from the object MyRecSet1. If you have populated this recordset why not just check the RecordCount property to see if there are any rows returned and disable the remove button if there are no rows.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.