VB.net文字数据类型:' 15D'转变为' 15'

时间:2014-12-14 22:02:19

标签: vb.net types

我遇到问题,我在数据库字段中使用数字和字母代码(" 15D")" Shortcut",但是当我检索它,即使它被视为一个字符串,VB.NET认为" D"代表小数并返回" 15"而不是字符串" 15D"存储在数据库中。

' assigning from DB
     Me.Filter1.ComboBox.ValueMember = "Shortcut"
     Me.Filter1.ComboBox.DisplayMember = "Description"
' using
     Dim myVal as String
     myVal = Me.Filter1.SelectedValue

... myVal是" 15"而不是" 15D"。

知道如何避免这种情况吗?

谢谢,

Libor的

1 个答案:

答案 0 :(得分:0)

您可以在阅读时将其转换为:

 Dim myVal as String =  Me.Filter1.SelectedValue
 myVal =New String((From c As Char In myVal Select c Where Char.IsDigit(c)).ToArray())

以不同的方式,你可以这样做: binding combobox from dictonary

    Dim dictonarySource As Dictionary(Of String, String)
    While reader.Read
        Dim shortCut As String = New String((From c As Char In reader.Items("Shortcut") Select c Where Char.IsDigit(c)).ToArray())
        dictonarySource.Add(shortCut, reader.Items("Description"))
    End While
    ComboBox1.DataSource = New BindingSource(dictonarySource, Nothing)
    ComboBox1.DisplayMember = "Value"
    ComboBox1.ValueMember = "Key"