need more help on split, replace and inserting into a databse

Discussion in 'ASP General' started by MrHelpMe, Oct 27, 2006.

  1. MrHelpMe

    MrHelpMe Guest

    Hello again experts,

    I have successfully pulled data from an LDAP server and now what I want
    to do is drop the data into a database table. The following is my code
    that will insert the data but that has problems.

    Code:
    FullName=Request.Form("Name")
    Email=Request.Form("Email")
    GivenName=Request.Form("GivenName")
    StreetAddress=Request.Form("StreetAddress")
    
    FullNameDesc = Replace(FullName, "'", "''")
    EmailDesc = Replace(Email, "'", "''")
    GivenNameDesc = Replace(GivenName, "'", "''")
    StreetAddressDesc = Replace(StreetAddress, "'", "''")
    
    strFullName = Split(FullNameDesc,", ")
    strEmailName = Split(EmailDesc,", ")
    strGivenName = Split(GivenNameDesc,", ")
    strStreetAddress = Split(StreetAddressDesc,", ")
    
    Response.Buffer = True
    Set objConn = Server.CreateObject("ADODB.Connection")
    objConn.ConnectionString = (ConnectionInfoHidden)
    objConn.Open
    
    For i = 0 to Ubound(strFullName)
    sSQL = "INSERT into Users (FullName, Email, GivenName,Address)"
    sSQL = sSQL & "VALUES ('" & strFullName(i) &"', '"& strEmailName(i)
    &"', '" & strGivenName(i) &"', '" & strStreetAddress(i) &"')"
    'objConn.Execute sSQL
    
    response.write sSql & "<BR>"
    Next
    
    
    What is happening is for each user the fullname, email, given name and
    address should get successfully entered into the database table however
    some fullnames are getting the incorrect email address, given name etc.
    while others are correct. Can anyone see a problem? I have checked the
    data that is coming back from ldap and my code is definitely incorrect.
    Why do some users get incorrect info...it's almost like they are
    getting the prior users info.
     
    MrHelpMe, Oct 27, 2006
    #1
    1. Advertising

  2. MrHelpMe

    MrHelpMe Guest

    Jon,

    Thanks for the reply. Is there any way you could show me this by
    example? I'm still trying to learn asp and not sure what you mean by
    "need to be more explicit in naming form fields". Does this require a
    restructuring of my code? I was hoping to implement minimal changes to
    my code. Could you possibly show me by using my exisiting code?
    Thanks Jon.


    Jon Paal wrote:
    > when you do a request.form there's no assurance that all fields collection will arrive in a relatively correct order.
    > You can verify this with a response.write stament follwing request.form for each field type. You will likely need to be more
    > explicit in naming form fields to create the desired association.
    >
    >
    >
    > "MrHelpMe" <> wrote in message news:...
    > > Hello again experts,
    > >
    > > I have successfully pulled data from an LDAP server and now what I want
    > > to do is drop the data into a database table. The following is my code
    > > that will insert the data but that has problems.
    > >
    > >
    Code:
    > > FullName=Request.Form("Name")
    > > Email=Request.Form("Email")
    > > GivenName=Request.Form("GivenName")
    > > StreetAddress=Request.Form("StreetAddress")
    > >
    > > FullNameDesc = Replace(FullName, "'", "''")
    > > EmailDesc = Replace(Email, "'", "''")
    > > GivenNameDesc = Replace(GivenName, "'", "''")
    > > StreetAddressDesc = Replace(StreetAddress, "'", "''")
    > >
    > > strFullName = Split(FullNameDesc,", ")
    > > strEmailName = Split(EmailDesc,", ")
    > > strGivenName = Split(GivenNameDesc,", ")
    > > strStreetAddress = Split(StreetAddressDesc,", ")
    > >
    > > Response.Buffer = True
    > > Set objConn = Server.CreateObject("ADODB.Connection")
    > > objConn.ConnectionString = (ConnectionInfoHidden)
    > > objConn.Open
    > >
    > > For i = 0 to Ubound(strFullName)
    > > sSQL = "INSERT into Users (FullName, Email, GivenName,Address)"
    > > sSQL = sSQL & "VALUES ('" & strFullName(i) &"', '"& strEmailName(i)
    > > &"', '" & strGivenName(i) &"', '" & strStreetAddress(i) &"')"
    > > 'objConn.Execute sSQL
    > >
    > > response.write sSql & "<BR>"
    > > Next
    > >
    > > 
    > >
    > > What is happening is for each user the fullname, email, given name and
    > > address should get successfully entered into the database table however
    > > some fullnames are getting the incorrect email address, given name etc.
    > > while others are correct. Can anyone see a problem? I have checked the
    > > data that is coming back from ldap and my code is definitely incorrect.
    > > Why do some users get incorrect info...it's almost like they are
    > > getting the prior users info.
    > >
     
    MrHelpMe, Oct 27, 2006
    #2
    1. Advertising

  3. MrHelpMe

    MrHelpMe Guest

    That's exactly what I did as noted in the code shown.


    Jon Paal wrote:
    > give each form field a specific unique name
    >
    > FullName1=Request.Form("Name1")
    >
    >
    > "MrHelpMe" <> wrote in message news:...
    > > Jon,
    > >
    > > Thanks for the reply. Is there any way you could show me this by
    > > example? I'm still trying to learn asp and not sure what you mean by
    > > "need to be more explicit in naming form fields". Does this require a
    > > restructuring of my code? I was hoping to implement minimal changes to
    > > my code. Could you possibly show me by using my exisiting code?
    > > Thanks Jon.
    > >
    > >
    > > Jon Paal wrote:
    > >> when you do a request.form there's no assurance that all fields collection will arrive in a relatively correct order.
    > >> You can verify this with a response.write stament follwing request.form for each field type. You will likely need to be more
    > >> explicit in naming form fields to create the desired association.
    > >>
    > >>
    > >>
    > >> "MrHelpMe" <> wrote in message news:...
    > >> > Hello again experts,
    > >> >
    > >> > I have successfully pulled data from an LDAP server and now what I want
    > >> > to do is drop the data into a database table. The following is my code
    > >> > that will insert the data but that has problems.
    > >> >
    > >> >
    Code:
    > >> > FullName=Request.Form("Name")
    > >> > Email=Request.Form("Email")
    > >> > GivenName=Request.Form("GivenName")
    > >> > StreetAddress=Request.Form("StreetAddress")
    > >> >
    > >> > FullNameDesc = Replace(FullName, "'", "''")
    > >> > EmailDesc = Replace(Email, "'", "''")
    > >> > GivenNameDesc = Replace(GivenName, "'", "''")
    > >> > StreetAddressDesc = Replace(StreetAddress, "'", "''")
    > >> >
    > >> > strFullName = Split(FullNameDesc,", ")
    > >> > strEmailName = Split(EmailDesc,", ")
    > >> > strGivenName = Split(GivenNameDesc,", ")
    > >> > strStreetAddress = Split(StreetAddressDesc,", ")
    > >> >
    > >> > Response.Buffer = True
    > >> > Set objConn = Server.CreateObject("ADODB.Connection")
    > >> > objConn.ConnectionString = (ConnectionInfoHidden)
    > >> > objConn.Open
    > >> >
    > >> > For i = 0 to Ubound(strFullName)
    > >> > sSQL = "INSERT into Users (FullName, Email, GivenName,Address)"
    > >> > sSQL = sSQL & "VALUES ('" & strFullName(i) &"', '"& strEmailName(i)
    > >> > &"', '" & strGivenName(i) &"', '" & strStreetAddress(i) &"')"
    > >> > 'objConn.Execute sSQL
    > >> >
    > >> > response.write sSql & "<BR>"
    > >> > Next
    > >> >
    > >> > 
    > >> >
    > >> > What is happening is for each user the fullname, email, given name and
    > >> > address should get successfully entered into the database table however
    > >> > some fullnames are getting the incorrect email address, given name etc.
    > >> > while others are correct. Can anyone see a problem? I have checked the
    > >> > data that is coming back from ldap and my code is definitely incorrect.
    > >> > Why do some users get incorrect info...it's almost like they are
    > >> > getting the prior users info.
    > >> >

    > >
     
    MrHelpMe, Oct 27, 2006
    #3
  4. MrHelpMe

    MrHelpMe Guest

    What is happening is the data is being returned from a select on an
    LDAP server. Then I am looping thorugh the recordeset and returning the
    objectrecordset of each field. What I am left with is for each field I
    have a string of comma separated list that I would need to split so
    that is why.


    I Jon Paal wrote:
    > if it is unique then why are you splitting it ?
    >
    >
    > "MrHelpMe" <> wrote in message news:...
    > > That's exactly what I did as noted in the code shown.
    > >
    > >
    > > Jon Paal wrote:
    > >> give each form field a specific unique name
    > >>
    > >> FullName1=Request.Form("Name1")
    > >>
    > >>
    > >> "MrHelpMe" <> wrote in message news:...
    > >> > Jon,
    > >> >
    > >> > Thanks for the reply. Is there any way you could show me this by
    > >> > example? I'm still trying to learn asp and not sure what you mean by
    > >> > "need to be more explicit in naming form fields". Does this require a
    > >> > restructuring of my code? I was hoping to implement minimal changes to
    > >> > my code. Could you possibly show me by using my exisiting code?
    > >> > Thanks Jon.
    > >> >
    > >> >
    > >> > Jon Paal wrote:
    > >> >> when you do a request.form there's no assurance that all fields collection will arrive in a relatively correct order.
    > >> >> You can verify this with a response.write stament follwing request.form for each field type. You will likely need to be more
    > >> >> explicit in naming form fields to create the desired association.
    > >> >>
    > >> >>
    > >> >>
    > >> >> "MrHelpMe" <> wrote in message news:...
    > >> >> > Hello again experts,
    > >> >> >
    > >> >> > I have successfully pulled data from an LDAP server and now what I want
    > >> >> > to do is drop the data into a database table. The following is my code
    > >> >> > that will insert the data but that has problems.
    > >> >> >
    > >> >> >
    Code:
    > >> >> > FullName=Request.Form("Name")
    > >> >> > Email=Request.Form("Email")
    > >> >> > GivenName=Request.Form("GivenName")
    > >> >> > StreetAddress=Request.Form("StreetAddress")
    > >> >> >
    > >> >> > FullNameDesc = Replace(FullName, "'", "''")
    > >> >> > EmailDesc = Replace(Email, "'", "''")
    > >> >> > GivenNameDesc = Replace(GivenName, "'", "''")
    > >> >> > StreetAddressDesc = Replace(StreetAddress, "'", "''")
    > >> >> >
    > >> >> > strFullName = Split(FullNameDesc,", ")
    > >> >> > strEmailName = Split(EmailDesc,", ")
    > >> >> > strGivenName = Split(GivenNameDesc,", ")
    > >> >> > strStreetAddress = Split(StreetAddressDesc,", ")
    > >> >> >
    > >> >> > Response.Buffer = True
    > >> >> > Set objConn = Server.CreateObject("ADODB.Connection")
    > >> >> > objConn.ConnectionString = (ConnectionInfoHidden)
    > >> >> > objConn.Open
    > >> >> >
    > >> >> > For i = 0 to Ubound(strFullName)
    > >> >> > sSQL = "INSERT into Users (FullName, Email, GivenName,Address)"
    > >> >> > sSQL = sSQL & "VALUES ('" & strFullName(i) &"', '"& strEmailName(i)
    > >> >> > &"', '" & strGivenName(i) &"', '" & strStreetAddress(i) &"')"
    > >> >> > 'objConn.Execute sSQL
    > >> >> >
    > >> >> > response.write sSql & "<BR>"
    > >> >> > Next
    > >> >> >
    > >> >> > 
    > >> >> >
    > >> >> > What is happening is for each user the fullname, email, given name and
    > >> >> > address should get successfully entered into the database table however
    > >> >> > some fullnames are getting the incorrect email address, given name etc.
    > >> >> > while others are correct. Can anyone see a problem? I have checked the
    > >> >> > data that is coming back from ldap and my code is definitely incorrect.
    > >> >> > Why do some users get incorrect info...it's almost like they are
    > >> >> > getting the prior users info.
    > >> >> >
    > >> >

    > >
     
    MrHelpMe, Oct 27, 2006
    #4
  5. MrHelpMe

    MrHelpMe Guest

    Jon,

    I do see what you mean but not understanding how to fix this with code.
    Your last statement "you either need to have unique names or an
    association value to correlate name with the intended email etc" could
    you show me how I would fix this please. Could you possible show me
    with some code? Thanks again for your help Jon.


    Jon Paal wrote:
    > I can only cvomment based upon what you have provided. Your code indicates it is coming from a form ("request.form").
    >
    > You can't allow multiple select of names and multiple select of emails and somehow hope they correspond to each other in the correct
    > order.
    >
    > there is nothing unique here, there is a collection of values which are split.
    >
    > > FullName=Request.Form("Name")
    > > FullNameDesc = Replace(FullName, "'", "''")
    > > strFullName = Split(FullNameDesc,", ")

    >
    > the resulting strFullName array is not likely to match with resulting array of emails in the correct order.
    >
    > you either need to have unique names or an association value to correlate name with the intended email etc.
    >
    >
    > "MrHelpMe" <> wrote in message news:...
    > > What is happening is the data is being returned from a select on an
    > > LDAP server. Then I am looping thorugh the recordeset and returning the
    > > objectrecordset of each field. What I am left with is for each field I
    > > have a string of comma separated list that I would need to split so
    > > that is why.
    > >
    > >
    > > I Jon Paal wrote:
    > >> if it is unique then why are you splitting it ?
    > >>
    > >>
    > >> "MrHelpMe" <> wrote in message news:...
    > >> > That's exactly what I did as noted in the code shown.
    > >> >
    > >> >
    > >> > Jon Paal wrote:
    > >> >> give each form field a specific unique name
    > >> >>
    > >> >> FullName1=Request.Form("Name1")
    > >> >>
    > >> >>
    > >> >> "MrHelpMe" <> wrote in message news:...
    > >> >> > Jon,
    > >> >> >
    > >> >> > Thanks for the reply. Is there any way you could show me this by
    > >> >> > example? I'm still trying to learn asp and not sure what you mean by
    > >> >> > "need to be more explicit in naming form fields". Does this require a
    > >> >> > restructuring of my code? I was hoping to implement minimal changes to
    > >> >> > my code. Could you possibly show me by using my exisiting code?
    > >> >> > Thanks Jon.
    > >> >> >
    > >> >> >
    > >> >> > Jon Paal wrote:
    > >> >> >> when you do a request.form there's no assurance that all fields collection will arrive in a relatively correct order.
    > >> >> >> You can verify this with a response.write stament follwing request.form for each field type. You will likely need to be
    > >> >> >> more
    > >> >> >> explicit in naming form fields to create the desired association.
    > >> >> >>
    > >> >> >>
    > >> >> >>
    > >> >> >> "MrHelpMe" <> wrote in message news:...
    > >> >> >> > Hello again experts,
    > >> >> >> >
    > >> >> >> > I have successfully pulled data from an LDAP server and now what I want
    > >> >> >> > to do is drop the data into a database table. The following is my code
    > >> >> >> > that will insert the data but that has problems.
    > >> >> >> >
    > >> >> >> >
    Code:
    > >> >> >> > FullName=Request.Form("Name")
    > >> >> >> > Email=Request.Form("Email")
    > >> >> >> > GivenName=Request.Form("GivenName")
    > >> >> >> > StreetAddress=Request.Form("StreetAddress")
    > >> >> >> >
    > >> >> >> > FullNameDesc = Replace(FullName, "'", "''")
    > >> >> >> > EmailDesc = Replace(Email, "'", "''")
    > >> >> >> > GivenNameDesc = Replace(GivenName, "'", "''")
    > >> >> >> > StreetAddressDesc = Replace(StreetAddress, "'", "''")
    > >> >> >> >
    > >> >> >> > strFullName = Split(FullNameDesc,", ")
    > >> >> >> > strEmailName = Split(EmailDesc,", ")
    > >> >> >> > strGivenName = Split(GivenNameDesc,", ")
    > >> >> >> > strStreetAddress = Split(StreetAddressDesc,", ")
    > >> >> >> >
    > >> >> >> > Response.Buffer = True
    > >> >> >> > Set objConn = Server.CreateObject("ADODB.Connection")
    > >> >> >> > objConn.ConnectionString = (ConnectionInfoHidden)
    > >> >> >> > objConn.Open
    > >> >> >> >
    > >> >> >> > For i = 0 to Ubound(strFullName)
    > >> >> >> > sSQL = "INSERT into Users (FullName, Email, GivenName,Address)"
    > >> >> >> > sSQL = sSQL & "VALUES ('" & strFullName(i) &"', '"& strEmailName(i)
    > >> >> >> > &"', '" & strGivenName(i) &"', '" & strStreetAddress(i) &"')"
    > >> >> >> > 'objConn.Execute sSQL
    > >> >> >> >
    > >> >> >> > response.write sSql & "<BR>"
    > >> >> >> > Next
    > >> >> >> >
    > >> >> >> > 
    > >> >> >> >
    > >> >> >> > What is happening is for each user the fullname, email, given name and
    > >> >> >> > address should get successfully entered into the database table however
    > >> >> >> > some fullnames are getting the incorrect email address, given name etc.
    > >> >> >> > while others are correct. Can anyone see a problem? I have checked the
    > >> >> >> > data that is coming back from ldap and my code is definitely incorrect.
    > >> >> >> > Why do some users get incorrect info...it's almost like they are
    > >> >> >> > getting the prior users info.
    > >> >> >> >
    > >> >> >
    > >> >

    > >
     
    MrHelpMe, Oct 27, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ashish M Bhonkiya
    Replies:
    0
    Views:
    446
    Ashish M Bhonkiya
    May 5, 2004
  2. JIM.H.

    q: design a web and databse

    JIM.H., Feb 13, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    345
    John Timney \(ASP.NET MVP\)
    Feb 13, 2005
  3. sreenivasan alakappan

    non-form based databse application

    sreenivasan alakappan, Apr 2, 2004, in forum: C++
    Replies:
    6
    Views:
    345
    Christopher Benson-Manica
    Apr 8, 2004
  4. Jim Florence
    Replies:
    4
    Views:
    664
    Jim Florence
    Jun 24, 2006
  5. Sirisha
    Replies:
    1
    Views:
    413
    Peter Bradley
    Feb 20, 2007
Loading...

Share This Page