每当我从数据库中选择数据并在组合框中显示时,都会显示未处理错误IndexOutOfRange的错误,位置0处没有行。
str = "select * from [Inventory_Remove] where [Inventory_r_id]=" & selectedRow.Cells(0).Value & ""
cmd = New OleDb.OleDbCommand(str, cn)
da.SelectCommand = cmd
da.Fill(ds, "Inventory_Remove")
If ds.Tables.Count > 0 AndAlso ds.Tables("Inventory_Remove").Rows.Count > 0 Then
For i As Integer = 0 To ds.Tables("Inventory_Remove").Rows.Count - 1
sell_inventory_id.Text = ds.Tables("Inventory_Remove").Rows(i)(0).ToString
name.SelectedIndex = name.FindString(ds.Tables("Inventory_Remove").Rows(i)(1).ToString)
size.SelectedIndex = size.FindString(ds.Tables("Inventory_Remove").Rows(i)(2).ToString)
piece.Text = ds.Tables("Inventory_Remove").Rows(i)(3).ToString
sell_inventory_date.Value = ds.Tables("Inventory_Remove").Rows(i)(4).ToString
description.Text = ds.Tables("Inventory_Remove").Rows(i)(5).ToString
type.Text = ds.Tables("Inventory_Remove").Rows(i)(6).ToString
If name.Text = "Rumali" Then
ppp2.Text = ds.Tables("Inventory_Remove").Rows(i)(7).ToString
Else
ppp.Text = ds.Tables("Inventory_Remove").Rows(i)(7).ToString
End If
totalprice.Text = ds.Tables("Inventory_Remove").Rows(i)(8).ToString
Next
End If
这是我的代码,其中名称和大小为组合框,并且在行size.SelectedIndex = size.FindString(ds.Tables("Inventory_Remove").Rows(i)(2).ToString)
上显示错误,并且当表单加载时,如果按名称的索引更改可能是按大小加载数据,这就是导致错误的原因