0

我正在制作一个 silverlight 5 应用程序并使用 RIA WCS 服务连接到 sql,我可以添加数据、删除数据、编辑数据并获取所有数据,但问题是我需要检索特定记录而不是整个实体,当我尝试以下代码时,什么也没发生:

Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click ' InitializeComponent() objctx = New BanksDomainContext Dim itemType = Branch_NameComboBox.SelectedItem.GetType Dim pi = itemType.GetProperty(Branch_NameComboBox.DisplayMemberPath) Dim cbi = pi.GetValue(Branch_NameComboBox.SelectedItem, Nothing).ToString() Dim BranchName As String = cbi

    '   Dim query As EntityQuery(Of Branches) = objctx.GetBranchesDetailsQuery(BranchName)

    '  Dim loadOp As LoadOperation(Of Branches) = Me.objctx.Load(query)
    '  DataGrid1.ItemsSource = loadOp.Entities
    '  objctx.Load(query, LoadData, Nothing)

    Dim loadOp = Me.objctx.Load(Me.objctx.GetBranchesDetailsQuery(BranchName))


    LoadData(loadOp)


End Sub
Private Sub LoadData(lo As LoadOperation)

    For Each br As Branches In lo.Entities

        AddressTextBlock.Text = br.Address
        CoordinatesTextBlock.Text = br.Coordinates
        ManagerTextBlock.Text = br.Manager
        PhoneTextBlock.Text = br.Phone
        FaxTextBlock.Text = br.Fax        
Next

End Sub

有人可以指导我怎么做吗?

4

1 回答 1

0

以下是通过从列表框中选择搜索词来从 SQL 记录加载文本框的解决方案:

Private Sub Branch_NameComboBox_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs) Handles Branch_NameComboBox.SelectionChanged
    m_PushpinLayer.Children.Clear()
    objctx = New BanksDomain
    Dim itemType = Branch_NameComboBox.SelectedItem.[GetType]()
    Dim pi = itemType.GetProperty(Branch_NameComboBox.DisplayMemberPath)
    Dim cbi = pi.GetValue(Branch_NameComboBox.SelectedItem, Nothing).ToString()
    Dim BranchName As String = cbi
    Dim itemType2 = NameComboBox.SelectedItem.[GetType]()
    Dim pi2 = itemType2.GetProperty(NameComboBox.DisplayMemberPath)
    Dim cbi2 = pi2.GetValue(NameComboBox.SelectedItem, Nothing).ToString()
    Dim BankName As String = cbi2
    Dim bb As EntityQuery(Of Branches) = From b In objctx.GetBranchesDetailsQuery(BranchName) Where b.Bank = BankName Select b



    Dim res As LoadOperation(Of Branches) = objctx.Load(bb, New Action(Of LoadOperation(Of Branches))(AddressOf GetBeansCompleted), True)

End Sub
Private Sub GetBeansCompleted(args As LoadOperation(Of Branches))


    For Each bc As Branches In args.Entities
        ' 
        Dim Latitude As Double = bc.Lat
        Dim Longitude As Double = bc.Lon

        Dim CoO As Location = New Location

        CoO.Latitude = Decimal.Parse(Latitude)
        CoO.Longitude = Decimal.Parse(Longitude)

        Dim BName As String = bc.Branch_Name.ToString
        Dim MKColor As Color = GetThisColor(bc.MapKeyColor.ToString)




        AddPushPin(BName, CoO, MKColor)

        AddressTextBlock.Text = (bc.Address.ToString)
        LatTextBlock.Text = (Decimal.Parse(Latitude))
        LonTextBlock.Text = (Convert.ToDecimal(Longitude))
        ManagerTextBlock.Text = (bc.Manager.ToString)
        PhoneTextBlock.Text = (bc.Phone.ToString)
        FaxTextBlock.Text = (bc.Fax.ToString)



    Next


End Sub
于 2012-12-10T10:10:31.830 回答