Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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中比较整数的LINQ查询_Vb.net_Linq - Fatal编程技术网

VB.net中比较整数的LINQ查询

VB.net中比较整数的LINQ查询,vb.net,linq,Vb.net,Linq,我试图编写一个LINQ查询,将数据库中的整数值与整变量进行比较。这是行不通的。我可以比较文本值,但比较整数会返回空值 Private Sub txtRoomNum_TextChanged(sender As Object, e As EventArgs) Handles txtRoomNum.TextChanged If Val(txtRoomNum.Text) > 99 Then Dim intRoomNum As Integer

我试图编写一个LINQ查询,将数据库中的整数值与整变量进行比较。这是行不通的。我可以比较文本值,但比较整数会返回空值

        Private Sub txtRoomNum_TextChanged(sender As Object, e As EventArgs) Handles txtRoomNum.TextChanged
    If Val(txtRoomNum.Text) > 99 Then
        Dim intRoomNum As Integer

        intRoomNum = Val(txtRoomNum.Text)
        Dim RoomData = (From Rooms In BadermanIslandDataSet.Rooms
                        Where Rooms.HotelID = intHotelID).SingleOrDefault
        ''Where Rooms.HotelID = intHotelID And Rooms.RoomNumber = intRoomNum
        Try
            txtTest.Text = RoomData.RoomID
        Catch ex As Exception
            txtTest.Text = "null"
        End Try
    End If


End Sub

更改
txtest.Text=RoomData.RoomID

to
Convert.ToInt32(txtest.Text)=RoomData.RoomID)


您之前比较了
string
integer
,因为它是用户输入,所以从文本字段获取值时,我会尝试使用integer.TryParse。这将防止引发异常,如果解析失败,您可以要求用户仅使用该字段中的数字

If Integer.TryParse(txtRoomNum.Text, intRoomNum) Then
   ...your logic
Else
   ...something to let them know to only put a number in txtRoomNum.Text
End If

好的,我发现了问题。我需要表格上的RoomsBindingSource。一旦添加了该选项,它就会像冠军一样工作。

打开选项
intRoomNum=Val(txtRoomNum.Text)
正在为整数赋值Double,问题出在查询本身。它的当前形式是比较Rooms.HotelID和intHotelID。这给了我一个空值。我试着直接输入一个数字,但仍然不起作用。打开选项Strict,你会发现更多的问题。好吧,排序a有效。如果我在1号酒店找房间,它可以工作,否则就不行。当前代码如下所示…如果Int32.TryParse(txtRoomNum.Text,intRoomNum)将Dim intRoomNum设置为整数,如果intRoomNum>99,则尝试Dim RoomInfo=(来自BadermanIslandDataSet.Rooms中的Rooms,其中Rooms.HotelID=intHotelID和Rooms.RoomNumber=intRoomNum选择Rooms.RoomID)intromid=RoomInfo.First Catch ex As Exception End Try txtest.Text=intromid End If Else End If