不关闭数据连接的严重后果

做了一个DATAGRID,要按两次删除才能在屏幕上显示删除后的结果,整了两天,检查才知道是数据连接没关

以下是错误的:
Public Overloads Shared Sub delrecord(ByVal myid As Integer)
        Dim myconnection As New OleDbConnection(CommunityGlobals.ConnectionString)
        Dim mycommand As OleDbCommand = New OleDbCommand("delete from articles where id=" & myid, myconnection)
        myconnection.Open()
        mycommand.ExecuteNonQuery()
        ' myconnection.Close()
    End Sub
以下是正确的:
Public Overloads Shared Sub delrecord(ByVal myid As Integer)
        Dim myconnection As New OleDbConnection(CommunityGlobals.ConnectionString)
        Dim mycommand As OleDbCommand = New OleDbCommand("delete from articles where id=" & myid, myconnection)
        myconnection.Open()
        mycommand.ExecuteNonQuery()
         myconnection.Close()
    End Sub

你可能感兴趣的:(ASP.NET工作日志)