I am using the following code to retrieve the last entered value from a table and insert it into a textbox called rf.

The code below works but the DB remains open until I restart my computer.

Sub Page_Load()

If Request.QueryString("VesselName") Is Nothing Then
            VesselName.Text = "Blank Name" 'some default value
        Else
            VesselName.Text = Request.QueryString("VesselName")

        End If
		
		'construct the command object and open a connection to the Returns table
        Dim dbconn, sql, dbcomm, dbread
        dbconn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("AnnexII.mdb"))

        dbconn.Open()
        sql = "SELECT Ref FROM Returns WHERE VesselName = '" & Trim(VesselName.Text) & "'"

       
        dbcomm = New OleDbCommand(sql, dbconn)
        dbread = dbcomm.ExecuteReader()


        If dbread.Read Then
            rf.Text = dbread(0)


            dbread.Close()

            dbconn.Close()
	
       End If

	   

End Sub
</script>

THanks ViRiPuFF

The Title should read DB ot BD sorry

ViRiPuff

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.