Link to home
Start Free TrialLog in
Avatar of keilandpullen
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.post.MyCompany.com:389/o=MyCompany.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.Connection")
    LDAP_CONN.Provider = "ADsDSOObject"
    LDAP_CONN.Provider = "ADsDSOObject"
    LDAP_CONN.Open()
    LDAP_COM = CreateObject("ADODB.Command")
    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").ToString)
    Me.hdnLDAPTelephone.Value = Trim(stlPost("telephonenumber").ToString)

  Catch ex As Exception
    Me.pnMessage.Visible = True
  End Try
ASKER CERTIFIED SOLUTION
Avatar of OliWarner
OliWarner

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Carl Tawn
If feasible you should convert to ADO.Net instead, making use of SqlConnection or OleDbConnection objects instead.