keilandpullen
asked on
ASP.NET 2.0 convert CreateObject("ADODB.Connection") to csharp
Hello,
I am using the following in ASP.NET 2.0 VB and need to convert it to csharp. The problem I am having is with creating an ADODB.Connection equivalent.
Dim stlPost As SortedList = New SortedList()
Dim strValue As String = ""
Me.lblMessageText.Text = ""
Dim LDAP_CONN As Object, LDAP_COM As Object, RS As Object
Dim tmp As Object = "", Item As Object = ""
Dim strFields As String = "ntUserDomainId, employeeNumber, uid, cn, telephonenumber, mail "
Dim strLDAP As String = "'LDAP://ldap-uscentral.po st.MyCompa ny.com:389 /o=MyCompa ny.com/ou= people' "
Dim strWhere01 As String = "WHERE employeenumber='" & strHRID & "' "
Dim strWhere02 As String = "OR uid='" & strHRID & "'"
Dim strSQL As String = "SELECT " & strFields & " FROM " & strLDAP & strWhere01 & strWhere02 & " ORDER BY sn"
Try
LDAP_CONN = CreateObject("ADODB.Connec tion")
LDAP_CONN.Provider = "ADsDSOObject"
LDAP_CONN.Provider = "ADsDSOObject"
LDAP_CONN.Open()
LDAP_COM = CreateObject("ADODB.Comman d")
LDAP_COM.ActiveConnection = LDAP_CONN
RS = LDAP_CONN.Execute(strSQL)
For Each Item In Split(Replace(strFields, " ", ""), ",")
tmp = RS(Item).Value
strValue = tmp(0).ToString
If Item.ToString = "ntUserDomainId" Then strValue = tmp ' Can't handle "\" in na02\sckeels
stlPost.Add(Item.ToString, strValue)
'Me.lblPost.Text &= Item.ToString & ": " & tmp(0).ToString & "<br />"
'Response.Write(Item & ": " & tmp(0) & "<br />") 'If Not IsNull(tmp) Then Response.Write(tmp(0))
Next
stlPost.TrimToSize() ' Trim the list
'Asign values from Array
Dim strCN As String = stlPost("cn").ToString
Me.hdnLDAPLastName.Value = Trim(Left(strCN, InStrRev(strCN, ",") - 1))
Me.hdnLDAPFirstName.Value = Trim(Mid(strCN, InStrRev(strCN, ",") + 1))
Me.hdnLDAPEmail.Value = Trim(stlPost("mail").ToStr ing)
Me.hdnLDAPTelephone.Value = Trim(stlPost("telephonenum ber").ToSt ring)
Catch ex As Exception
Me.pnMessage.Visible = True
End Try
I am using the following in ASP.NET 2.0 VB and need to convert it to csharp. The problem I am having is with creating an ADODB.Connection equivalent.
Dim stlPost As SortedList = New SortedList()
Dim strValue As String = ""
Me.lblMessageText.Text = ""
Dim LDAP_CONN As Object, LDAP_COM As Object, RS As Object
Dim tmp As Object = "", Item As Object = ""
Dim strFields As String = "ntUserDomainId, employeeNumber, uid, cn, telephonenumber, mail "
Dim strLDAP As String = "'LDAP://ldap-uscentral.po
Dim strWhere01 As String = "WHERE employeenumber='" & strHRID & "' "
Dim strWhere02 As String = "OR uid='" & strHRID & "'"
Dim strSQL As String = "SELECT " & strFields & " FROM " & strLDAP & strWhere01 & strWhere02 & " ORDER BY sn"
Try
LDAP_CONN = CreateObject("ADODB.Connec
LDAP_CONN.Provider = "ADsDSOObject"
LDAP_CONN.Provider = "ADsDSOObject"
LDAP_CONN.Open()
LDAP_COM = CreateObject("ADODB.Comman
LDAP_COM.ActiveConnection = LDAP_CONN
RS = LDAP_CONN.Execute(strSQL)
For Each Item In Split(Replace(strFields, " ", ""), ",")
tmp = RS(Item).Value
strValue = tmp(0).ToString
If Item.ToString = "ntUserDomainId" Then strValue = tmp ' Can't handle "\" in na02\sckeels
stlPost.Add(Item.ToString,
'Me.lblPost.Text &= Item.ToString & ": " & tmp(0).ToString & "<br />"
'Response.Write(Item & ": " & tmp(0) & "<br />") 'If Not IsNull(tmp) Then Response.Write(tmp(0))
Next
stlPost.TrimToSize() ' Trim the list
'Asign values from Array
Dim strCN As String = stlPost("cn").ToString
Me.hdnLDAPLastName.Value = Trim(Left(strCN, InStrRev(strCN, ",") - 1))
Me.hdnLDAPFirstName.Value = Trim(Mid(strCN, InStrRev(strCN, ",") + 1))
Me.hdnLDAPEmail.Value = Trim(stlPost("mail").ToStr
Me.hdnLDAPTelephone.Value = Trim(stlPost("telephonenum
Catch ex As Exception
Me.pnMessage.Visible = True
End Try
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If feasible you should convert to ADO.Net instead, making use of SqlConnection or OleDbConnection objects instead.