Please help i would like to delete using the customerid only how can i restrict this using b4xtable
B4X:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
Private sql As SQL
End Sub
Sub Globals
Private B4XTable1 As B4XTable
Private XUI As XUI
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
CopyDBIfNeeded("chinook.db")
sql.Initialize(File.DirInternal, "chinook.db", False)
End If
Activity.LoadLayout("1")
B4XTable1.AddColumn("Customer Id", B4XTable1.COLUMN_TYPE_NUMBERS)
B4XTable1.AddColumn("Name", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("Company", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("Address", B4XTable1.COLUMN_TYPE_TEXT)
Dim Data As List
Data.Initialize
Dim rs As ResultSet = sql.ExecQuery("SELECT CustomerId, FirstName, LastName, Company, Address FROM customers")
Do While rs.NextRow
Dim row(4) As Object
row(0) = rs.GetDouble("CustomerId")
row(1) = rs.GetString("FirstName") & " " & rs.GetString("LastName")
row(2) = rs.GetString("Company")
'Some of the fields are Null. We need to convert them to empty strings:
If row(2) = Null Then row(2) = ""
row(3) = rs.GetString("Address")
Data.Add(row)
Loop
rs.Close
B4XTable1.SetData(Data)
End Sub
Sub B4XTable1_CellClicked (ColumnId As String, RowId As Long)
Dim sf As Object = XUI.Msgbox2Async("Delete row?", "Title", "Yes", "Cancel", "No", Null)
Wait For (sf) Msgbox_Result (Result As Int)
If Result = XUI.DialogResponse_Positive Then
'DeleteRow(B4XTable1, RowId)
Dim kkt As String = RowId
Log(kkt)
Dim column As B4XTableColumn = B4XTable1.GetColumn(ColumnId)
Dim value As String = B4XTable1.GetRow(RowId).Get(ColumnId)
Dim kt As String
Dim ktn As String
kt = value
ktn= column.Id
Log(kt)
Log(ktn)
'Dim m As Map = B4XTable1.GetRow(RowId)
DeleteRow(B4XTable1, kt)
End If
End Sub
Sub DeleteRow (tbl As B4XTable, CustomerId As Int)
Dim kk As String = CustomerId
Log(kk)
sql.ExecNonQuery2("DELETE FROM customers WHERE CustomerId = ?", Array (CustomerId))
Dim page As Int = tbl.CurrentPage
Dim FirstIndex As Int = tbl.FirstRowIndex
tbl.ClearDataView 'Updates the rows count.
If FirstIndex + 1 >= tbl.mCurrentCount Then
page = page - 1
End If
tbl.CurrentPage = page
B4XTable1.Clear
B4XTable1.AddColumn("Customer Id", B4XTable1.COLUMN_TYPE_NUMBERS)
B4XTable1.AddColumn("Name", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("Company", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("Address", B4XTable1.COLUMN_TYPE_TEXT)
Dim Data As List
Data.Initialize
Dim rs As ResultSet = sql.ExecQuery("SELECT CustomerId, FirstName, LastName, Company, Address FROM customers")
Do While rs.NextRow
Dim row(4) As Object
row(0) = rs.GetDouble("CustomerId")
row(1) = rs.GetString("FirstName") & " " & rs.GetString("LastName")
row(2) = rs.GetString("Company")
'Some of the fields are Null. We need to convert them to empty strings:
If row(2) = Null Then row(2) = ""
row(3) = rs.GetString("Address")
Data.Add(row)
Loop
rs.Close
B4XTable1.SetData(Data)
End Sub
Sub CopyDBIfNeeded (Filename As String)
If File.Exists(File.DirInternal, Filename) = False Then
File.Copy(File.DirAssets, Filename, File.DirInternal, Filename)
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub