Using Arrays to write data to SQL Server

B

Brett_A

I'm trying to write data from a form using a text box (textarea) that
has a return after each item. For example:

(e-mail address removed)
(e-mail address removed)
(e-mail address removed)
(e-mail address removed)

I'm getting the data written to the SQL server table fine, but every
item after the first is getting written with a special character
preceeding the email address that looks like a little box. What is
it, why is their there and how do I remove it?

Here is my code:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
Dim varItems, varArray, I
varItems = Request("email_address")
varArray = Split(varItems,chr(13))

For I = LBound(varArray) To UBound(varArray)

'write data to database

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "driver={SQL Server};server=aaaaaaa;"
SQLStmt = "INSERT INTO tbl_advertisers (email_address) "
SQLStmt = SQLStmt & "VALUES ('" & varArray(I) & "')"
Set RS = Conn.Execute(SQLStmt)
set rs=nothing

If err.number>0 then
response.write "VBScript Errors Occured:" & "<P>"
response.write "Error Number=" & err.number & "<P>"
response.write "Error Descr.=" & err.description & "<P>"
response.write "Help Context=" & err.helpcontext & "<P>"
response.write "Help Path=" & err.helppath & "<P>"
response.write "Native Error=" & err.nativeerror & "<P>"
response.write "Source=" & err.source & "<P>"
response.write "SQLState=" & err.sqlstate & "<P>"
end if
IF conn.errors.count> 0 then
response.write "Database Errors Occured" & "<P>"
response.write SQLstmt & "<P>"
for counter= 0 to conn.errors.count
response.write "Error #" & conn.errors(counter).number & "<P>"
response.write "Error desc. -> " & conn.errors(counter).description &
"<P>"
next
else
end if
Conn.Close
set conn=nothing

Next 'I
%>


Thanks.

Brett
 
F

Farshad Hemmati

The reason you are getting that symbol is because you are splitting the text
incorrectly. By splitting it with the Chr(13), you are forgetting that a new
line is Chr(13) + Chr(10).

The best way is to replace that line with the following:
varArray = Split(varItems, vbNewLine)

Your problem should be fixed.
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top