Ok, asked before but didn't get exactly what i was looking for soooooo
Any of you vb.net experts (with some vb6 experience) got a few minutes to convert this VB6 code to VB.net? It would help me a lot to see how this is done in .net
I have a lot of need for something like the code below that will scan a table and make corrections to the database, user error, whatever.
From what i've read, you'd need one sub/function to read all the records and another for the update - and each of these would need to be coded specifically for each table
The code below was just tossed together to get the point across (IE the GUID function I know exists in .net - where in vb6 i had a function that generated the code)
Many thanks in advance!
Global DB As New ADODB.Connection
Global RS As New Recordset
Sub Main
OpenDB "SQLServer", "UserName", "Password", "Database", DB
OpenRecordset rsXRef, "Select * from XRef", DB
' --------- This is the point in question
With rsXRef
While Not .EOF ' Loop through all the records
If Len(RTrim(!GUID)) < 5 Then ' If an edit is required...
!GUID = GUID ' Make the update
End If
.Update ' and update the record
.MoveNext ' move to the next record and repeat...
Wend
End With
' ---------
End Sub
Function GUID
GUID = "SomeRandomGUID"
End Function
Function OpenDB(SQLServer, User, Password, Database, dbConnection As ADODB.Connection) As Boolean
dbConnection.ConnectionString = "Provider='SQLOLEDB.1' ;User id='" & User & "' ;password='" & Password & "' ;Persist Security info='True' ; Data Source='" & SQLServer & "'; Initial Catalog='" & Database & "'; Connect Timeout=2;"
dbConnection.Open
OpenDB = True
End Function
Public Function OpenRecordset(RS As Recordset, SQL As String, Conn As ADODB.Connection) As Boolean
OpenRecordset = True
With RS
On Error Resume Next
If .State = adStateOpen Then
.Close
End If
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.CursorLocation = adUseClient
.Open SQL, Conn
End With
Exit Function
End Function