Code: Select all
' Visual Basic
Dim qry As String = "SELECT * FROM Users WHERE Login = ?;"
Dim connection As OleDbConnection = New OleDbConnection
connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Desktop\pool.accdb"
Dim cmd As OleDbCommand = New OleDbCommand(qry, connection)
cmd.Connection.Open()
Dim par As New OleDbParameter
par.Value = Environ("UserName")
cmd.Parameters.Add(par)
Dim result As Object = cmd.ExecuteScalar
cmd.Connection.Close()
If result Is Nothing Then
Stop
End If
Code: Select all
; PureBasic
Dim qry.s = "SELECT * FROM Users WHERE Login = ?;"
Dim db.i = 1
Dim result.b
UseODBC()
OpenDatabase(db, "dbPool")
SetDatabaseString(db, 0, UserName())
QueryDatabase(db, qry)
result = NextDatabaseRow(db)
CloseDatabase(db)
If result = 0
CallDebugger
EndIf
(Can you simplify the VB code? What I'm posting is the best of my efforts.)
But just look, to set a parameter. In PureBasic, you choose whether it's string or numeric and use the appropriate function -- SetDatabase[String/Long](internal database number, ordinal number of the parameter within the collection of parameters, parameter value). That's it.
In VB, you have to create an object of type Parameter, set the value of the parameter, and then add the parameter to the collection of parameters!