Sunday, October 01, 2006

Using ObjectDataSource in code

There is an easy way to use a objectdatasource in VB.Net code. Drag an objectdatasource control on your webform.
Then, in the page load event, use the following code:

Dim mySource As ObjectDataSource = ObjectDataSource1
Dim result As IEnumerable = mySource.Select()
Dim row As DataRowView

For Each row In result
'your code here
'you can acces any field in a row:
' myString = row("table field name")
Next

No comments: