[CODE lang="b4x" title="Main (MSSQL.b4j)"]#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#AdditionalJar: jtds-1.3.1.jar
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Public SQL1 As SQL
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.Show
Dim PagesManager As B4XPagesManager
PagesManager.Initialize(MainForm)
SQL1.Initialize2("net.sourceforge.jtds.jdbc.Driver", "jdbc:jtds:sqlserver://Aeric-HP;databaseName=MyDatabase;instance=SQLEXPRESS;integratedSecurity=true", "sa", "password")
End Sub
'Template version: B4J-1.0
#Region Delegates
Sub MainForm_FocusChanged (HasFocus As Boolean)
B4XPages.Delegate.MainForm_FocusChanged(HasFocus)
End Sub
Sub MainForm_Resize (Width As Double, Height As Double)
B4XPages.Delegate.MainForm_Resize(Width, Height)
End Sub
Sub MainForm_Closed
B4XPages.Delegate.MainForm_Closed
End Sub
Sub MainForm_CloseRequest (EventData As Event)
B4XPages.Delegate.MainForm_CloseRequest(EventData)
End Sub
Public Sub MainForm_IconifiedChanged (Iconified As Boolean)
B4XPages.Delegate.MainForm_IconifiedChanged(Iconified)
End Sub
#End Region[/CODE]
[CODE lang="b4x" title="B4XMainPage (B4XMainPage.bas)"]#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=MSSQL.zip
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Private Sub Button1_Click
GetData
End Sub
Private Sub GetData
Dim strSQL As String = $"SELECT TOP 10 * FROM [MyDatabase].[dbo].[Users] WHERE id > ?"$
Dim strResult As String
Dim RS As ResultSet = Main.SQL1.ExecQuery2(strSQL, Array As String(1))
Do While RS.NextRow
strResult = strResult & RS.GetString("id") & ":" & RS.GetString("usrname") & CRLF
Loop
RS.Close
Log(strResult)
End Sub[/CODE]
SQL:
USE [MyDatabase]
GO
/****** Object: Table [dbo].[users] Script Date: 8/11/2021 1:15:29 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[users](
[id] [int] IDENTITY(1,1) NOT NULL,
[usrname] [varchar](50) NULL,
CONSTRAINT [PK_users] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
SET IDENTITY_INSERT [dbo].[users] ON
GO
INSERT [dbo].[users] ([id], [usrname]) VALUES (1, N'Speman tab')
GO
INSERT [dbo].[users] ([id], [usrname]) VALUES (2, N'Proximol Ganules')
GO
INSERT [dbo].[users] ([id], [usrname]) VALUES (3, N'Renanive caps')
GO
INSERT [dbo].[users] ([id], [usrname]) VALUES (4, N'Uvamin retard')
GO
INSERT [dbo].[users] ([id], [usrname]) VALUES (5, N'Melatonin')
GO
SET IDENTITY_INSERT [dbo].[users] OFF
GO