CSDN博客

img xuandhu

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

发表于2004/10/22 16:09:00  717人阅读

分类: ASP.NET工作日志

做了一个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

阅读全文
0 0

相关文章推荐

img
取 消
img