I just wanted to ask why my data duplicates and how can I prevent it?
NOTE: my SQL query are working properly, the only problem is that every data it saves are duplicated based on the last value of ctr
Here is my code:
For Each lvi As ListViewItem In lvReportFormat2.Items
Dim count = lvReportFormat2.Items.Count
Dim ctr = 0
Dim orderby = 0
label.Text = lvReportFormat2.Items(ctr).SubItems(4).Text
Do While ctr < count
Label1.Text = lvReportFormat2.Items(ctr).SubItems(4).Text
Execute("INSERT INTO tblrptChad (accountcode,accountdesc,Type,class,Orderby,ReportType,Formula,Show)VALUES ('" & IIf(lvReportFormat2.Items(ctr).SubItems(0).Text IsNot DBNull.Value, lvReportFormat2.Items(ctr).SubItems(0).Text, "NULL") & "','" & IIf(lvReportFormat2.Items(ctr).SubItems(1).Text IsNot DBNull.Value, lvReportFormat2.Items(ctr).SubItems(1).Text, "NULL") & "','" & IIf(lvReportFormat2.Items(ctr).SubItems(2).Text IsNot DBNull.Value, lvReportFormat2.Items(ctr).SubItems(2).Text, "NULL") & "','" & IIf(lvReportFormat2.Items(ctr).SubItems(3).Text IsNot DBNull.Value, lvReportFormat2.Items(ctr).SubItems(3).Text, "NULL") & "','" & orderby & "','" & Val(IIf(lvReportFormat2.Items(ctr).SubItems(5).Text IsNot DBNull.Value, Val(lvReportFormat2.Items(ctr).SubItems(5).Text), 0)) & "','" & IIf(lvReportFormat2.Items(ctr).SubItems(6).Text IsNot DBNull.Value, lvReportFormat2.Items(ctr).SubItems(6).Text, "NULL") & "','" & Val(IIf(lvReportFormat2.Items(ctr).SubItems(7).Text IsNot DBNull.Value, Val(lvReportFormat2.Items(ctr).SubItems(7).Text), 0)) & "')")
ctr = ctr + 1
orderby = orderby + 1
Loop
Next