Private ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\aspxWeb.mdb;Persist Security Info=True"
Private cn1 As OleDbConnection
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not Page.IsPostBack Then
Dim cn As OleDbConnection = New OleDbConnection(ConnectionString)
cn.Open
cn1 = New OleDbConnection(ConnectionString)
cn1.Open
Dim cmd As OleDbCommand = New OleDbCommand("select * from [Subject]", cn)
Dim dr As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
MasterGridView.DataSource = dr
MasterGridView.DataBind
dr.Close
cmd.Dispose
cn.Dispose
cn1.Dispose
cn = cn1 = Nothing
End If
End Sub
Protected Sub MasterGridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim oGridView As GridView = CType(e.Row.FindControl("DetailGridView"), GridView)
If Not (oGridView Is Nothing) Then
Dim cmd As OleDbCommand = New OleDbCommand("select top 10 * from Document Where pid = " + MasterGridView.DataKeys(e.Row.RowIndex).Value, cn1)
Dim dr1 As OleDbDataReader = cmd.ExecuteReader
oGridView.DataSource = dr1
oGridView.DataBind
dr1.Close
cmd.Dispose
End If
End If
End Sub
评论