I am having some problems regarding the dataview object in vb.net. I have a search form built that searches a table called customers and what i want it to do is it finds more then 1 result it will display a a datagrid with the results which works fine but if it only finds one result it will show a databounded form to a dataview which has a relationship to the quotes table and displays all the quotes for that customer. When it only finds one record it displays it fine but i have code that takes values from the child rows and sends them to a function and displays the returned results in a grid column and when i execute that function it throws an exception sayin cannot create child list for field customers any ideas ? below is the code that displays the grid column and below that is the function that i call which is well tested and returns the right values. any help will be greated appreciated thanks It works fine when i had the form bounded to the corresponding dataset!
Public Sub DispBldgSize()
Dim myIndex As Integer = BindingContext (myDv, "customers").Position
Dim myHeight As Double
Dim myDvChd As DataView
Dim myDvRow As DataRowView
Dim myWidth, myLength, myDoor As Integer
Dim myChild As Object = myDvChd.Item(myIndex).CreateChildView("custquotes")
For Each myDvRow In myChild
If IsDBNull(myDvRow("bldg_width")) Then
myWidth = 0
Else
myWidth = myDvRow("bldg_width")
End If
If IsDBNull(myDvRow("bldg_length")) Then
myLength = 0
Else
myLength = myDvRow("bldg_length")
End If
If IsDBNull(myDvRow("bldg_height")) Then
myHeight = 0
Else
myHeight = myDvRow("bldg_height")
End If
If IsDBNull(myDvRow("door_height")) Then
myDoor = 0
Else
myDoor = myDvRow("door_height")
End If
Next
myDvRow("bldg_size") = CalcBldgSize(myWidth, myLength, myHeight, myDoor)
End Sub
Public Function CalcBldgSize(ByVal bWidth As Integer, ByVal _
bLength As Integer, ByVal bHeight As Double, ByVal dHeight As Integer) As String
Dim myHeightI, myHeightF As Integer
Dim mySize As String, myFraction As Double
If bWidth = 0 Or bLength = 0 Or bHeight = 0 Then
CalcBldgSize = "N/A"
Else
bHeight += (dHeight / 12)
myHeightF = Conversion.Fix(bHeight)
myFraction = bHeight - (Conversion.Fix(bHeight))
myHeightI = Math.Round(myFraction * 12)
mySize = bWidth & "' W x " & bLength & "' L x "
If myHeightI = 0 Then
mySize &= myHeightF & "' H"
Else
mySize &= myHeightF & "' " & myHeightI & ControlChars.Quote & " H"
End If
CalcBldgSize = mySize
End If
End Function
dataview issues
-
- Posts: 37
- Joined: Fri 11 Feb 2005 19:18
sorry for the repeat post
I am having some problems regarding the dataview object in vb.net. I have a search form built that searches a table called customers and what i want it to do is it finds more then 1 result it will display a a datagrid with the results which works fine but if it only finds one result it will show a databounded form to a dataview which has a relationship to the quotes table and displays all the quotes for that customer. When it only finds one record it displays it fine but i have code that takes values from the child rows and sends them to a function and displays the returned results in a grid column and when i execute that function it throws an exception sayin cannot create child list for field customers any ideas ? below is the code that displays the grid column and below that is the function that i call which is well tested and returns the right values. any help will be greated appreciated thanks It works fine when i had the form bounded to the corresponding dataset!
Public Sub DispBldgSize()
Dim myIndex As Integer = BindingContext (myDv, "customers").Position
Dim myHeight As Double
Dim myDvChd As DataView
Dim myDvRow As DataRowView
Dim myWidth, myLength, myDoor As Integer
Dim myChild As Object = myDvChd.Item(myIndex).CreateChildView("custquotes")
For Each myDvRow In myChild
If IsDBNull(myDvRow("bldg_width")) Then
myWidth = 0
Else
myWidth = myDvRow("bldg_width")
End If
If IsDBNull(myDvRow("bldg_length")) Then
myLength = 0
Else
myLength = myDvRow("bldg_length")
End If
If IsDBNull(myDvRow("bldg_height")) Then
myHeight = 0
Else
myHeight = myDvRow("bldg_height")
End If
If IsDBNull(myDvRow("door_height")) Then
myDoor = 0
Else
myDoor = myDvRow("door_height")
End If
Next
myDvRow("bldg_size") = CalcBldgSize(myWidth, myLength, myHeight, myDoor)
End Sub
Public Function CalcBldgSize(ByVal bWidth As Integer, ByVal _
bLength As Integer, ByVal bHeight As Double, ByVal dHeight As Integer) As String
Dim myHeightI, myHeightF As Integer
Dim mySize As String, myFraction As Double
If bWidth = 0 Or bLength = 0 Or bHeight = 0 Then
CalcBldgSize = "N/A"
Else
bHeight += (dHeight / 12)
myHeightF = Conversion.Fix(bHeight)
myFraction = bHeight - (Conversion.Fix(bHeight))
myHeightI = Math.Round(myFraction * 12)
mySize = bWidth & "' W x " & bLength & "' L x "
If myHeightI = 0 Then
mySize &= myHeightF & "' H"
Else
mySize &= myHeightF & "' " & myHeightI & ControlChars.Quote & " H"
End If
CalcBldgSize = mySize
End If
End Function
Public Sub DispBldgSize()
Dim myIndex As Integer = BindingContext (myDv, "customers").Position
Dim myHeight As Double
Dim myDvChd As DataView
Dim myDvRow As DataRowView
Dim myWidth, myLength, myDoor As Integer
Dim myChild As Object = myDvChd.Item(myIndex).CreateChildView("custquotes")
For Each myDvRow In myChild
If IsDBNull(myDvRow("bldg_width")) Then
myWidth = 0
Else
myWidth = myDvRow("bldg_width")
End If
If IsDBNull(myDvRow("bldg_length")) Then
myLength = 0
Else
myLength = myDvRow("bldg_length")
End If
If IsDBNull(myDvRow("bldg_height")) Then
myHeight = 0
Else
myHeight = myDvRow("bldg_height")
End If
If IsDBNull(myDvRow("door_height")) Then
myDoor = 0
Else
myDoor = myDvRow("door_height")
End If
Next
myDvRow("bldg_size") = CalcBldgSize(myWidth, myLength, myHeight, myDoor)
End Sub
Public Function CalcBldgSize(ByVal bWidth As Integer, ByVal _
bLength As Integer, ByVal bHeight As Double, ByVal dHeight As Integer) As String
Dim myHeightI, myHeightF As Integer
Dim mySize As String, myFraction As Double
If bWidth = 0 Or bLength = 0 Or bHeight = 0 Then
CalcBldgSize = "N/A"
Else
bHeight += (dHeight / 12)
myHeightF = Conversion.Fix(bHeight)
myFraction = bHeight - (Conversion.Fix(bHeight))
myHeightI = Math.Round(myFraction * 12)
mySize = bWidth & "' W x " & bLength & "' L x "
If myHeightI = 0 Then
mySize &= myHeightF & "' H"
Else
mySize &= myHeightF & "' " & myHeightI & ControlChars.Quote & " H"
End If
CalcBldgSize = mySize
End If
End Function