提问人:misteriomarcos 提问时间:3/17/2023 最后编辑:Tusharmisteriomarcos 更新时间:3/17/2023 访问量:28
为什么当我在 datagridview1 中按搜索两次时出现接收错误?
Why im receveing error when I press search twice in datagridview1?
问:
我有这个代码,我认为似乎工作正常,当我编写代码并按回车键在txt_searchProduct_barcode处搜索时,插入 datagridview1 并在列中显示所有产品信息到目前为止一切正常,但是当我再次搜索以计算quatity和总数时......在最后一列中,它总是给出价格列中零的结果,以及 datagridview1 的最后一列,这里是子代码......
Dim exist As Boolean = False, numrow As Integer = 0, numtext As Integer
For Each itm As DataGridViewRow In DataGridView1.Rows
If itm.Cells(0).Value IsNot Nothing Then
If itm.Cells(1).Value.ToString = txt_searchProduct_barcode.Text Then
exist = True
numrow = itm.Index
numtext = CInt(itm.Cells(8).Value)
Exit For
End If
End If
Next
If exist = False Then
Try
conn.Open()
cmd = New MySqlCommand("SELECT * FROM `tblproduct` WHERE `procode`='" & txt_searchProduct_barcode.Text & "'", conn)
dr = cmd.ExecuteReader
While dr.Read()
If txt_searchProduct_barcode.Text = String.Empty Then
Return
Else
'Create new row.
' `procode`, `proname` , `progroup` , `uom` , `location` , `price` , `tax` , `totalprice`
Dim procode As String = dr("procode")
Dim Proname As String = dr("proname")
Dim Progroup As String = dr("progroup")
Dim uom As String = dr("uom")
Dim Price As Decimal = dr("price")
Dim tax As Decimal = dr("tax")
Dim totalprice As Decimal = dr("totalprice")
Dim totalqtyprice As Double
totalqtyprice = Price * tax / 100 + Price
DataGridView1.Rows.Add(DataGridView1.Rows.Count + 1, procode, Proname, Progroup, uom, Price, tax, totalprice, 1, totalqtyprice)
End If
End While
Catch ex As Exception
MsgBox(ex.Message)
Finally
conn.Close()
End Try
Else
DataGridView1.Rows(numrow).Cells(8).Value = CInt("1") + numtext
DataGridView1.Rows(numrow).Cells(9).Value = DataGridView1.Rows(numrow).Cells(7).Value * DataGridView1.Rows(numrow).Cells(8).Value
End If
End Sub
我想了解错误在哪里以及如何更改。谢谢
答: 暂无答案
上一个:更新查询阻止空参数更新列
评论