I've had little time to learn VB.Net and am struggling with the new methods of connecting to databases. I have just found that if I include a reference to the "Microsoft ActiveX Data Objects 2.8 Library" COM object - just as I would have done in VB6 - I can use a lot of my old VB6 code with just minor changes.
The question is: Am I handicapping myself by doing things this way? Are these old COM objects still supported in VB2008?
Here's an example of my standard db connection module, modified very slightly to work in VB2005:
I then call this sub with something like:Code:Module Module1 Public GcnCon As ADODB.Connection Public GrsRec As ADODB.Recordset Public GsDBpath As String Sub Open_DB(ByVal SQL As String) Try GcnCon = New ADODB.Connection GcnCon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & GsDBpath GcnCon.Open() GrsRec = New ADODB.Recordset GrsRec.CursorLocation = ADODB.CursorLocationEnum.adUseClient GrsRec.Open(SQL, GcnCon, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockPessimistic) Catch ex As Exception MsgBox(ex.Message) End Try End Sub Sub Close_ADO() Try System.Runtime.InteropServices.Marshal.ReleaseComObject(GcnCon) System.Runtime.InteropServices.Marshal.ReleaseComObject(GrsRec) Catch ex As Exception MsgBox(ex.Message) End Try End Sub End Module
GsDBpath = "n:\mydata.mdb"
Call Open_db("Select * from tblCustomers")
and then
Call Close_ADO
when I'm finished with the db.
Any reason why I shouldn't do this in VB.Net?




Reply With Quote