Results 1 to 4 of 4

Thread: RE: DataTable Select method and binding

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    11

    Angry RE: DataTable Select method and binding

    This is getting urgent - someone please help...

    I have a datatable "Employees" with bound fields on a form. I use the following code to find a specific record - this works well:

    Function Find(ByVal sExpression As String) As CEmployeeRecd

    Dim DRs() As DataRow
    Dim DTEmployee As DataTable
    Dim EmployeeRecd As CEmployeeRecd

    Find = Nothing
    Try
    'Get reference to the Employee table...
    DTEmployee = m_DS.Tables("Employees")

    DRs = DTEmployee.Select(sExpression)
    If DRs.GetLength(0) <> 0 Then
    EmployeeRecd = New CEmployeeRecd()
    If Not IsDBNull(DRs(0)("LastName")) Then
    EmployeeRecd.LastName = CStr(DRs(0)("LastName"))
    End If
    If Not IsDBNull(DRs(0)("FirstName")) Then
    EmployeeRecd.FirstName = CStr(DRs(0)("FirstName"))
    End If
    ...

    Find = EmployeeRecd
    End If
    Catch Ex As Exception
    Throw Ex
    End Try

    I now want the bound controls to show the found datarow. How do i achieve this in code.
    (The Datarow class has an rowID field - which is private. I was hoping to set the
    BindingManagerBase.postion to rowID - this isn't possible). Any ideas.

    Thanks

  2. #2
    Lively Member
    Join Date
    Sep 2002
    Location
    Belgium
    Posts
    99
    O/T answer :

    First of all, I should take a look at the three-tier design.
    You should split up your presentation layer and your business layer.

    Read your data in a new class Employee with all it's properties and then you can databind it easier to the Employee object.

    There you can handle your find for a record. Probably you need to cast your dataset to a dataview with

    Dim dv as dataview = ds.tables(0).defaultview
    dv.find="city='Berlin'"

    You should handle all these things in your business layer.

    Check this out :
    http://msdn.microsoft.com/library/en...asp?frame=true

    Bjorn

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    11

    Wink Sorted

    Thanks - for the suggestion. Actually i had created a class with all the db access stuff and passed the Dataset back to the from for binding. I 've made the mods using a dataview and it works!

    Cheers

  4. #4
    Lively Member
    Join Date
    Sep 2002
    Location
    Belgium
    Posts
    99
    You 're welcome

    If you have 3-tier, things sort out easilier ! It's a little more work but you get a payback !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width