Avatar of Kamran Mahmood
Kamran Mahmood

asked on 

I would like to DELETE more than one record from DB , using Asp.net vb & MS Access

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim cell As TableCell = e.Row.Cells(4)
            Dim cell2 As TableCell = e.Row.Cells(6)
            Dim mytxtboxdepart As TextBox = e.Row.FindControl("txtBoxDeparture")
            Dim mytxtboxstays As TextBox = e.Row.FindControl("txtBoxStays")
            Dim mytxtboxcriteria As TextBox = e.Row.FindControl("txtBoxCriteria")

            Dim provider As String
            Dim connString As String
            Dim myconnection As OleDbConnection = New OleDbConnection
            provider = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("~/App_Data/myDB.mdb")
            connString = provider
            myconnection.ConnectionString = connString

            If Convert.ToDateTime(mytxtboxdepart.Text) < Convert.ToDateTime(mytxtboxstays.Text) Then
                cell2.BackColor = Color.Red
                Dim str As String
                str = "DELETE * FROM ReservationTb WHERE Criteria" = "5"
            End If
            command.Connection = myAccessConnection
        End If
    End Sub

But i am getting the error ...
ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.

ASP.NETVB ScriptMicrosoft Access

Avatar of undefined
Last Comment
Kamran Mahmood

8/22/2022 - Mon