Good evening group, I’m trying to understand how to improve my code: At the moment in the database I have two tables, IntestazioneFatturaAcquesti and CorpoFatturaAcquesti, in the first there are some data connected to the second table. The second table refers to the first through an ID. So in my search I display the invoice data and based on the ID the reference headers are inserted. As if that were not enough I can filter from the various data, an article within the invoice through 2 fields (even a partial search) and based on the Company Name.
So I wrote the following code, which works, but I think it is very slow. Is there a way to improve it?
'I choose what to look for
var Scelta As Integer
scelta=0
if Campo1="" and campo2="" then
scelta=0
end if
if Campo1<>"" and campo2="" then
scelta=1
end if
if Campo1="" and campo2<>"" then
scelta=2
end if
if Campo1<>"" and campo2<>"" then
scelta=3
end if
select case Scelta
Case 0
rows = db.SelectSQL("SELECT * FROM CorpoFatturaAcquisti")
Case 1
rows = db.SelectSQL("SELECT * FROM CorpoFatturaAcquisti Where Materiale_Spedito like '%" + Campo1 +"%' order by Materiale_Spedito")
Case 2
rows = db.SelectSQL("SELECT * FROM CorpoFatturaAcquisti Where Materiale_Spedito like '%" + Campo2 +"%' order by Materiale_Spedito")
Case 3
rows = db.SelectSQL("SELECT * FROM CorpoFatturaAcquisti Where Materiale_Spedito like '%" +Campo1 +"%' and Materiale_Spedito like '%" +Campo2 +"%' order by Materiale_Spedito")
End Select
While Not Rows.AfterLastRow
rows2 = db.SelectSQL("SELECT * FROM IntestazioneFatturaAcquisti Where ID="+ rows.Column("Id_IntestazioneFattura").StringValue)
if PopupMenu1.SelectedRowValue="" then ' NOT filter by company name
ListBoxRicerca.AddRow(rows2.Column("ID").StringValue,rows.Column("ID").StringValue,rows2.Column("Ditta").StringValue.ConvertEncoding(Encodings.WindowsANSI),rows2.Column("Data").DateTimeValue.SQLDate,rows2.Column("NumeroFattura").StringValue, rows.Column("Materiale_Spedito").StringValue.ConvertEncoding(Encodings.WindowsANSI))
else ' filter by company name
if PopupMenu1.SelectedRowValue=rows2.Column("Ditta").StringValue then
ListBoxRicerca.AddRow(rows2.Column("ID").StringValue,rows.Column("ID").StringValue,rows2.Column("Ditta").StringValue.ConvertEncoding(Encodings.WindowsANSI),rows2.Column("Data").DateTimeValue.SQLDate,rows2.Column("NumeroFattura").StringValue, rows.Column("Materiale_Spedito").StringValue.ConvertEncoding(Encodings.WindowsANSI))
end if
end if
rows.MoveToNextRow
Wend
rows2.close
rows.Close
P.S:I know my code is very basic, but I like programming as a hobby