我正在使用Try Catch,我想在 Form3.ListBoxes
中添加其他类型的 Form2.ListBoxes
项目 . 但它在 Catch
异常后停止添加 . 所以我想在异常被 grab 后保持 Loop
!
我的程序获得的产品和展示相同的产品,但在另一种类型(如:我有一个品牌的T恤,但我想要另一个品牌的“相同”T恤) .
ListBox5是我在Form1中添加的数量 . 我加载图像要清楚 . Form2列表框按顺序排列(ListBox1,ListBox2 ...) . Form2和Form3具有相同的设计 .
Dim ConnectionString As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & Application.StartupPath & "\Tabela_Precos.xlsx; Extended Properties=Excel 12.0;")
ConnectionString.Open()
Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
Dim da
For i = 0 To Form1.ListBox1.Items.Count - 1
Dim str As String = Form1.ListBox1.Items(i).ToString
Dim prod As String = str.Substring(2, 3)
da = New OleDbDataAdapter("SELECT * FROM [Mesa$] WHERE Format([Ref], ""000000000"") like '%" & prod & "%'", ConnectionString)
da.Fill(dt)
Try
ListBox1.Items.Add(dt.Rows(i).Item(0))
ListBox2.Items.Add(dt.Rows(i).Item(1))
ListBox3.Items.Add(dt.Rows(i).Item(3))
ListBox4.Items.Add(dt.Rows(i).Item(5))
ListBox5.Items.Add(Form1.ListBox5.Items(i))
ListBox6.Items.Add(ListBox4.Items(i) * ListBox5.Items(i))
Catch ex As Exception
End Try
Next
我需要Try-Catch . 我正在进行查询,如果不存在DataBase中的行则停止 . 停止后如何继续循环?
这些是程序运行的图像(它们被编辑):
1 回答
当你说"keep the loop after the catch"时,你自己回答了这个问题 . 您希望循环到 continue , resume 或移动到 next 迭代 . 所有这些都是VB关键字,我建议您查看For Next Statement以了解For循环的工作原理 .
以下是您可以通过以下几种方法之一 .
没有错误处理,只需忽略并继续: