|
-
Mar 2nd, 2004, 03:16 AM
#1
Thread Starter
New Member
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
-
Mar 3rd, 2004, 10:37 AM
#2
Lively Member
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
-
Mar 3rd, 2004, 12:17 PM
#3
Thread Starter
New Member
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
-
Mar 4th, 2004, 02:54 AM
#4
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|