在一本字典在vb.net中使用对象 [英] Using Objects in a dictionary in vb.net
问题描述
这是我如何检查我的字典 OCCURENCES
已包含键和值,并指定键和值吧......但我需要另一个值,所以如何我在这里使用的对象?
Occurences.Add(xRows.Cells(4).Value.ToString(),对象)
不知怎的,像这样的:
OCCURENCES(xRows.Cells(4).Value.ToString())= Double.Parse(点(xRows.Cells(4).Value.ToString())。的ToString( ))+<这里的第一个对象值>)
但是,这是我目前如何做到这一点,只有有一个键和一个值,但我需要像钥匙,它具有(值,值),类似的东西对象:
实际code:
如果(occurences.ContainsKey(xRows.Cells(4).Value.ToString()))然后
OCCURENCES(xRows.Cells(4).Value.ToString())= Double.Parse(点(xRows.Cells(4).Value.ToString())。的ToString())+ Double.Parse(xRows.Cells(7 ).Value.ToString())
其他
occurences.Add(xRows.Cells(4).Value.ToString(),Double.Parse(xRows.Cells(7).Value.ToString()))
万一下一个
然后我还有一个code为插入,我需要使用对象的第二个值。
使用commm作为新的MySqlCommand()
随着commm
.Parameters.Clear()
.Parameters.AddWithValue(@ iBrnchCde,cmbBrnch code.Text)
.Parameters.AddWithValue(@如果code,pair.Key)
.Parameters.AddWithValue(@ iDesc,<第二个对象的值HEREGT&;)
.Parameters.AddWithValue(@ iQty,pair.Value)
.CommandText = oInsertString
■连接= _conn
.CommandType = CommandType.Text
结束与
commm.ExecuteNonQuery()
使用完
执行以下操作:
类CustomRowObject
公共属性Name()作为字符串
公共财产数量()为双
公共属性Description()作为字符串
末级
如果(occurences.ContainsKey(xRows.Cells(4).Value.ToString()))然后
OCCURENCES(xRows.Cells(4).Value.ToString())。数量= Double.Parse(点(xRows.Cells(4).Value.ToString())。的ToString())+ Double.Parse(xRows.Cells (7).Value.ToString())
其他
occurences.Add(xRows.Cells(4).Value.ToString(),新CustomRowObject随着{.Name点= a.Cells(产品名称)。Value.ToString(),.描述= .Cells(ProductDesc)。 Value.ToString(),.Quantity = a.Cells(数量)。Value.ToString()})
万一下一个
然后通过 OCCURENCES(keynamegoeshere)引用它。数量
在你的SQL中使用。
This is how I Check if my dictionary occurences
already contains a key and a value and assign keys and values to it... but I need another value, so how do I use the object here?
Occurences.Add(xRows.Cells(4).Value.ToString(), Object)
Somehow like this:
occurences(xRows.Cells(4).Value.ToString()) = Double.Parse(occurences(xRows.Cells(4).Value.ToString()).ToString()) + <"1st object value here">)
But this is how I currently do it which only has a key and a value but I need something like key, object which has (value, value), something like that:
Actual code:
If (occurences.ContainsKey(xRows.Cells(4).Value.ToString())) Then
occurences(xRows.Cells(4).Value.ToString()) = Double.Parse(occurences(xRows.Cells(4).Value.ToString()).ToString()) + Double.Parse(xRows.Cells(7).Value.ToString())
Else
occurences.Add(xRows.Cells(4).Value.ToString(), Double.Parse(xRows.Cells(7).Value.ToString()))
End If
Next
Then i have another code for insert where i need to use the 2nd value of the object.
Using commm As New MySqlCommand()
With commm
.Parameters.Clear()
.Parameters.AddWithValue("@iBrnchCde", cmbBrnchCode.Text)
.Parameters.AddWithValue("@iFCode", pair.Key)
.Parameters.AddWithValue("@iDesc", <"2nd OBJECT VALUE HERE"> )
.Parameters.AddWithValue("@iQty", pair.Value)
.CommandText = oInsertString
.Connection = _conn
.CommandType = CommandType.Text
End With
commm.ExecuteNonQuery()
End Using
Do the following:
Class CustomRowObject
Public Property Name() As String
Public Property Quantity() As Double
Public Property Description() As String
End Class
If (occurences.ContainsKey(xRows.Cells(4).Value.ToString())) Then
occurences(xRows.Cells(4).Value.ToString()).Quantity = Double.Parse(occurences(xRows.Cells(4).Value.ToString()).ToString()) + Double.Parse(xRows.Cells(7).Value.ToString())
Else
occurences.Add(xRows.Cells(4).Value.ToString(),New CustomRowObject With { .Name = a.Cells("ProductName").Value.ToString(),.Description = .Cells("ProductDesc").Value.ToString(), .Quantity = a.Cells("Quantity").Value.ToString()})
End If
Next
Then reference it via occurences("keynamegoeshere").Quantity
for use in your SQL.
这篇关于在一本字典在vb.net中使用对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!