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

M

MrHelpMe

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.
 
M

MrHelpMe

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 said:
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 said:
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.
 
M

MrHelpMe

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


Jon said:
give each form field a specific unique name

FullName1=Request.Form("Name1")


MrHelpMe said:
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 said:
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.



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.
 
M

MrHelpMe

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.

if it is unique then why are you splitting it ?


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


Jon said:
give each form field a specific unique name

FullName1=Request.Form("Name1")


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.



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.
 
M

MrHelpMe

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 said:
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 said:
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.

if it is unique then why are you splitting it ?


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")


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.



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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top