Converting VBScript to VB .NET

bench

New member
Joined
Oct 23, 2006
Messages
3
Location
Manila, Philippines
Programming Experience
Beginner
How can I be able to convert the following codes (VBScript) to VB .NET:

VB.NET:
Dim dbs As DAO.Database
Dim rstContact As DAO.Recordset
Dim rstOptUser As DAO.Recordset
Dim reg_strUserName As String
 
' Open the Recordsets
Set dbs = CodeDb
If reg_strUserName = "" Then
Set rstOptUser = dbs.OpenRecordset("tblSMPreferenceUser", dbOpenSnapshot, dbSeeChanges)
Else
Set rstOptUser = dbs.OpenRecordset("SELECT * FROM tblSMPreferenceUser WHERE strUserName = """ & reg_strUserName & """", dbOpenSnapshot, dbSeeChanges)
End If
Set rstContact = dbs.OpenRecordset("SELECT * FROM tblARCustomer WHERE strClass = 'Customer' And ysnActive = True", dbOpenSnapshot, dbSeeChanges)
I hope somebody can help me regarding this issue.

Thanks,
Bench
 
Last edited by a moderator:
Try to check this one (I'd try to convert it to VB .NET but I am not so sure if I am doing this correctly):

VB.NET:
' Construct a SQL string and a connection object
Dim sql AsString = "SELECT * FROM tblARCustomer WHERE strClass = 'Customer' And ysnActive = True"
Dim sql2 AsString = "SELECT * FROM tblSMPreferenceUser WHERE strUserName = '" & _UserID & "'"
Dim conn As SqlClient.SqlConnection = New SqlClient.SqlConnection()
conn.ConnectionString = Configuration.Database.ConnectionString
' Open connection
If conn.State <> ConnectionState.Open Then
conn.Open()
EndIf
' Create a data adapter and data set
Dim adapter AsNew SqlClient.SqlDataAdapter(sql, conn)
Dim adapter2 AsNew SqlClient.SqlDataAdapter(sql2, conn)
Dim ds AsNew DataSet
 
' Fill data adapter
If _UserID <> ""Then
adapter2.Fill(ds, "SELECT * FROM tblSMPreferenceUser WHERE strUserName = '" & _UserID & "'")
EndIf
adapter.Fill(ds, "SELECT * FROM tblARCustomer WHERE strClass = 'Customer' And ysnActive = True")
 
' Clean up connection
If conn IsNothingThen
If conn.State = ConnectionState.Open Then
conn.Close()
EndIf
' Dispose connection
conn.Dispose()
EndIf
 
Last edited by a moderator:
Back
Top