Posted by tsymonds on September 7, 2009 – 2:14 pm
You may wish to update a data source using an event.
'You need to use FindControl to access control on a FormView:
Dim FirstName As TextBox = FormView1.FindControl("FirstNameTextBox")
Dim LastName As TextBox = FormView1.FindControl("LastNameTextBox")
Dim Phone As TextBox = FormView1.FindControl("PhoneTextBox")
Dim Email As TextBox = FormView1.FindControl("EmailTextBox")
SqlDataSource1.InsertParameters("FirstName").DefaultValue = FirstName
SqlDataSource1.InsertParameters("LastName").DefaultValue = LastName
SqlDataSource1.InsertParameters("Phone").DefaultValue = Phone
SqlDataSource1.InsertParameters("Email").DefaultValue = Email
SqlDataSource1.Insert()
And, this is the code for Update:
SqlDataSource1.UpdateParameters("FirstName").DefaultValue = FirstName
SqlDataSource1.UpdateParameters("LastName").DefaultValue = LastName
SqlDataSource1.UpdateParameters("Phone").DefaultValue = Phone
SqlDataSource1.UpdateParameters("Email").DefaultValue = Email
SqlDataSource1. Update()
Posted by tsymonds on August 5, 2009 – 9:22 am
The .NET Framework includes an API called System.DirectoryServices. The sample VB.NET code below shows how to retrieve user account properties from the Active Directory.
In order to use System.DirectoryServices classes, you will need to first add a reference to System.DirectoryServices.
Imports System.DirectoryServices is required at the very top of your VB.NET code.
Function GetUserProperties(ByVal GetUser, ByVal Result)
Dim objSearch As New DirectorySearcher
objSearch.SearchRoot = New DirectoryEntry("LDAP://dc=domain,dc=co,dc=uk")
objSearch.Filter = GetUser
'cn = Full Name, givenName = First name, initials = Middle names, sn = Surname, mail = email address
objSearch.PropertiesToLoad.AddRange(New String() {"cn", "giveName", "initials", "sn", "department", "mail", "Manager"})
Dim objResult As SearchResult
objResult = objSearch.FindOne()
GetUserProperties = (objResult.Properties(Result)(0))
End Function
Replace dc=domain, dc=co, dc=uk with your AD settings.