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(ByV al sender As Object, ByVal e As System.Web.UI.WebControls. GridViewRo wEventArgs ) 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("txtBoxD eparture")
Dim mytxtboxstays As TextBox = e.Row.FindControl("txtBoxS tays")
Dim mytxtboxcriteria As TextBox = e.Row.FindControl("txtBoxC riteria")
Dim provider As String
Dim connString As String
Dim myconnection As OleDbConnection = New OleDbConnection
provider = "Provider=Microsoft.Jet.OL EDB.4.0; Data Source=" & Server.MapPath("~/App_Data /myDB.mdb" )
connString = provider
myconnection.ConnectionStr ing = connString
If Convert.ToDateTime(mytxtbo xdepart.Te xt) < Convert.ToDateTime(mytxtbo xstays.Tex t) Then
myconnection.Open()
Response.Write(Convert.ToD ateTime(my txtboxdepa rt.Text))
cell2.BackColor = Color.Red
Dim str As String
str = "DELETE * FROM ReservationTb WHERE Criteria" = "5"
End If
command.Connection = myAccessConnection
command.ExecuteNonQuery()
myAccessConnection.Close()
End If
End Sub
But i am getting the error ...
ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.
PLS HELPPPPPP !!! EXPERTS
If e.Row.RowType = DataControlRowType.DataRow
Dim cell As TableCell = e.Row.Cells(4)
Dim cell2 As TableCell = e.Row.Cells(6)
Dim mytxtboxdepart As TextBox = e.Row.FindControl("txtBoxD
Dim mytxtboxstays As TextBox = e.Row.FindControl("txtBoxS
Dim mytxtboxcriteria As TextBox = e.Row.FindControl("txtBoxC
Dim provider As String
Dim connString As String
Dim myconnection As OleDbConnection = New OleDbConnection
provider = "Provider=Microsoft.Jet.OL
connString = provider
myconnection.ConnectionStr
If Convert.ToDateTime(mytxtbo
myconnection.Open()
Response.Write(Convert.ToD
cell2.BackColor = Color.Red
Dim str As String
str = "DELETE * FROM ReservationTb WHERE Criteria" = "5"
End If
command.Connection = myAccessConnection
command.ExecuteNonQuery()
myAccessConnection.Close()
End If
End Sub
But i am getting the error ...
ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.
PLS HELPPPPPP !!! EXPERTS
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Shaun for your help & support.
myconnection.Open()
should be outside of if statement