我有一个中继器,它在每次迭代中从多个表中获取数据。现在我一进入 OnItemDataBound 事件就打开连接并在事件完成之前关闭它。这意味着在我的情况下,连接打开和关闭超过 1000 次。这是正确的方法吗?还有其他方法吗?
我的代码基本上是这样的
Protected Sub myRepeater_OnItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs)
Try
mycon.open()
Dim RowView As DataRowView = e.Item.DataItem
//fetch data from 5 different tables using the data from the datasource (dataset)
mycon.close()
Catch ex As Exception
End Try
End Sub