Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VB.net文字数据类型:';15D';变成';15';_Vb.net_Types - Fatal编程技术网

VB.net文字数据类型:';15D';变成';15';

VB.net文字数据类型:';15D';变成';15';,vb.net,types,Vb.net,Types,我遇到了一个问题,我在数据库字段“快捷方式”中使用数字和字母代码(“15D”),但当我检索它时,即使它被视为字符串,VB.NET认为“D”代表十进制,并返回“15”,而不是数据库中存储的字符串“15D” ' assigning from DB Me.Filter1.ComboBox.ValueMember = "Shortcut" Me.Filter1.ComboBox.DisplayMember = "Description" ' using Dim myVal

我遇到了一个问题,我在数据库字段“快捷方式”中使用数字和字母代码(“15D”),但当我检索它时,即使它被视为字符串,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

您可以在读取时将其转换为以下格式:

 Dim myVal as String =  Me.Filter1.SelectedValue
 myVal =New String((From c As Char In myVal Select c Where Char.IsDigit(c)).ToArray())
您可以通过不同的方式执行以下操作:


您确定数据库中实际存储了15D而不是15吗?“快捷方式”字段的数据类型是什么?VB不关心,这里还有其他问题。@roryap是的,我确定数据带有“d”,只是小写。我甚至可以在描述中看到它,我在描述中使用CONCAT(快捷方式),description。我最好仔细检查一下过滤器设置(虽然我已经检查过了),如果不是我强制输入整数的话……这是SQL查询中很难找到的一个小小的键入错误;即使存在此错误,查询仍能正常工作,但导致ValueMember中输入的不是“快捷方式”,而是“ID”字段。谢谢,这似乎是一个很好的建议,但需要做一些更改,考虑到我必须在代码生成器和所有生成的实例中对其进行更改,我将尝试找到根本原因并首先解决它。
    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"