You find this example project in your Plugins Download as a Xojo project file within the examples folder: /SQL/Microsoft SQL via ODBC
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
dim con as new SQLConnectionMBS
try
// we used Microsoft SQL Server 2008 and run app on Windows to test this
con.Option("UseAPI") = "ODBC"
con.Connect(TextField1.text,"","",SQLConnectionMBS.kODBCClient)
con.Scrollable = false // disabling scrolling cursors is much faster for Microsoft SQL Server...
// go to database test
dim dcmd as new SQLCommandMBS(con, "use test")
dcmd.Execute
// select names from test table
dim cmd as new SQLCommandMBS(con, "select * from dbo.test")
cmd.Execute
while cmd.FetchNext
MsgBox cmd.Field("name").asStringValue
wend
// Disconnect is optional
// autodisconnect will ocur in destructor if needed
con.Disconnect
msgbox "We are disconnected!"
catch r as RuntimeException
MsgBox r.message
// SAConnection::Rollback()
// can also throw an exception
// (if a network error for example),
// we will be ready
try
// on error rollback changes
con.Rollback
catch rr as runtimeexception
MsgBox rr.message
end try
end try
End EventHandler
End Control
Control TextField1 Inherits TextField
ControlInstance TextField1 Inherits TextField
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar