2011年6月13日 星期一

ClearPool的用法

參考來源
--
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ft As GridViewRow = Me.GridView1.FooterRow
Dim tb4 As TextBox = CType(ft.FindControl("TextBox4"), TextBox)
Dim tb5 As TextBox = CType(ft.FindControl("TextBox5"), TextBox)
Dim tb6 As TextBox = CType(ft.FindControl("TextBox6"), TextBox)
Dim objconn As SqlConnection = New SqlConnection("Data Source=1361;Initial Catalog=SFC;Persist Security Info=True;User ID=sa;Password=123456")


objconn.Open()

SqlConnection.ClearPool(objconn)

Dim sql As String = "insert dbo.kentdm(c1,c2,c3) values('" & tb4.Text & "','" & tb5.Text & "','" & tb6.Text & "')"
Dim objcmd As SqlCommand = New SqlCommand(sql, objconn)
Try
objcmd.ExecuteNonQuery()
Me.GridView1.DataBind()
Catch ex As Exception
objconn.Close()
objconn.Dispose()
objcmd.Dispose()
sql = Nothing
Finally
objconn.Close()
objconn.Dispose()
objcmd.Dispose()
sql = Nothing
End Try
GC.Collect()
End Sub

沒有留言:

張貼留言