Mudplugger
Member
- Joined
- Aug 13, 2010
- Messages
- 6
- Programming Experience
- 10+
Hi Guys,
I am new here, but have over 10 years coding experience with VB and VBA. I decided it was probably about time I branched out and as VB.net was the closest to my skill set I am starting there.
I have an Access 2000 mdb app to port into VB.net & SQL Server Compact as a training excercise and I am already haveing trouble. I have decided to try to walk before running so rather than trying to learn VB.net and ADO.net at the same time I wanted to stick with ADO 2.7 as I am familiar with that.
So to the problem - whenever I open an ADO recordset regardless of the datasource (.mdb or .sdf) the recordset only opens as ForwardOnly and ReadOnly. I know this is the default state for an ADO recordset, but changing the .LockType, .CursorType or .CursorLocation properties makes no diference to the recordset. I have confirmed that both connections (.mdb & .sdf) are "Mode=ReadWrite" but I still can't get a writable recordset.
Can anyone help me please, I'm getting desperate.
Thanks in advance.
I am new here, but have over 10 years coding experience with VB and VBA. I decided it was probably about time I branched out and as VB.net was the closest to my skill set I am starting there.
I have an Access 2000 mdb app to port into VB.net & SQL Server Compact as a training excercise and I am already haveing trouble. I have decided to try to walk before running so rather than trying to learn VB.net and ADO.net at the same time I wanted to stick with ADO 2.7 as I am familiar with that.
So to the problem - whenever I open an ADO recordset regardless of the datasource (.mdb or .sdf) the recordset only opens as ForwardOnly and ReadOnly. I know this is the default state for an ADO recordset, but changing the .LockType, .CursorType or .CursorLocation properties makes no diference to the recordset. I have confirmed that both connections (.mdb & .sdf) are "Mode=ReadWrite" but I still can't get a writable recordset.
Can anyone help me please, I'm getting desperate.
VB.NET:
Module Module1
Dim oMDBConn As ADODB.Connection
Dim oSDFConn As ADODB.Connection
Public Sub OpenMDB()
Dim strDBPath As String
If oMDBConn Is Nothing Then
strDBPath = "C:\Users\Dave\Documents\Visual Studio 2010\Databases\vesta.mdb"
oMDBConn = New ADODB.Connection
With oMDBConn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Mode = ADODB.ConnectModeEnum.adModeReadWrite
.Open("Data Source=" & strDBPath)
End With
MsgBox("MDB Open = " & CStr(oMDBConn.State = 1))
Else
MsgBox("Connection is already open")
End If
End Sub
Public Sub OpenSDF()
Dim strDBPath As String
If oSDFConn Is Nothing Then
strDBPath = "C:\Users\Dave\Documents\Visual Studio 2010\Databases\VestaCerts.sdf"
oSDFConn = New ADODB.Connection
With oSDFConn
.ConnectionString = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=C:\Users\Dave\Documents\Visual " & _
"Studio 2010\Databases\VestaCerts.sdf;SSCE:Database Password=Vesta;"
.Mode = ADODB.ConnectModeEnum.adModeReadWrite
.Open()
End With
MsgBox("SDF Open = " & CStr(oSDFConn.State = 1))
Else
MsgBox("Connection is already open")
End If
End Sub
Public Function GetRecordSet(ByVal sSource As String, ByVal oDBConn As ADODB.Connection) As ADODB.Recordset
Dim oRs As ADODB.Recordset
oRs = New ADODB.Recordset
With oRs
.ActiveConnection = oDBConn
.Source = oDBConn.Execute(sSource)
.LockType = ADODB.LockTypeEnum.adLockOptimistic
.CursorType = ADODB.CursorTypeEnum.adOpenKeyset
.CursorLocation = ADODB.CursorLocationEnum.adUseClient
.Open(CursorType:=.CursorType, LockType:=.LockType)
End With
GetRecordSet = oRs
oRs = Nothing
End Function
Public Sub CloseDatabase(ByVal oDBConn As ADODB.Connection)
If Not oDBConn Is Nothing Then
If oDBConn.State = ADODB.ObjectStateEnum.adStateOpen Then
oDBConn.Close()
End If
End If
End Sub
Public Sub MigrateSkills()
Dim oRSsdf, oRSmdb As ADODB.Recordset
Dim strSQLsdf, strSQLmdb As String
strSQLmdb = "SELECT * FROM Attachment"
strSQLsdf = "SELECT * FROM Attachment"
oRSmdb = GetRecordSet(strSQLmdb, oMDBConn)
If Not oRSmdb.EOF Then
MsgBox("A Recordset!!")
oRSmdb.Close()
End If
oRSsdf = GetRecordSet(strSQLsdf, oSDFConn)
If Not oRSsdf.EOF Then
MsgBox("A Recordset!!")
oRSsdf.Close()
End If
End Sub
End Module
Thanks in advance.