473,473 Members | 1,947 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

reading text delimited

I have the below code found on an ASP site.

<%
arrName = Split(Request("TextArea"),",")
%>
<%
For i = LBound(arrName) To UBound(arrName)
Response.Write "ID: " & arrName(i) & "<br>"
Next
%>

I'm using a TextArea box to submit the following...
A123,1
B123,2
C123,3
Results are...
ID: A123
ID: 1 B123
ID: 2 C123
ID: 3
I expected something like...
A123 1
B123 2
C123 3
For the sake of understanding, why are the results like above?

In the end, I want to insert these values into a table.
A123 into Field1 .... 1 into Field2
B123 into Field1 .... 2 into Field2
C123 into Field1 .... 3 into Field2

Where do I start?
thanks!
Mar 14 '06 #1
23 1966

shank wrote:
I have the below code found on an ASP site.

<%
arrName = Split(Request("TextArea"),",")
%>
<%
For i = LBound(arrName) To UBound(arrName)
Response.Write "ID: " & arrName(i) & "<br>"
Next
%>

I'm using a TextArea box to submit the following...
A123,1
B123,2
C123,3
Results are...
ID: A123
ID: 1 B123
ID: 2 C123
ID: 3
I expected something like...
A123 1
B123 2
C123 3
For the sake of understanding, why are the results like above?

In the end, I want to insert these values into a table.
A123 into Field1 .... 1 into Field2
B123 into Field1 .... 2 into Field2
C123 into Field1 .... 3 into Field2

Where do I start?
thanks!


You have chosen the comma as a delimiter in your example, so split()
breaks the string into an array wherever it sees a comma.

If you are actually inputting content like this:

A123,1
B123,2
C123,3

then the line breaks are what delimit your values. Your code should be
like this:

arrName = Split(Request.Form("TextArea"),chr(13))

Then you need to replace the commas with spaces within your for... next
loop:

For i = 0 To UBound(arrName)
Response.Write "ID: " & replace(arrName(i),","," ") & "<br>"
Next

By the way - you should define the collection in the Request Object you
want to reference (eg Request.Form, Request.QueryString). If you
don't, ASP will search all the collections, starting with
ServerVariables, and that is an expensive process in terms of overhead.

--
Mike Brind

Mar 14 '06 #2

"Mike Brind" <pa*******@hotmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...

shank wrote:
I have the below code found on an ASP site.

<%
arrName = Split(Request("TextArea"),",")
%>
<%
For i = LBound(arrName) To UBound(arrName)
Response.Write "ID: " & arrName(i) & "<br>"
Next
%>

I'm using a TextArea box to submit the following...
A123,1
B123,2
C123,3
Results are...
ID: A123
ID: 1 B123
ID: 2 C123
ID: 3
I expected something like...
A123 1
B123 2
C123 3
For the sake of understanding, why are the results like above?

In the end, I want to insert these values into a table.
A123 into Field1 .... 1 into Field2
B123 into Field1 .... 2 into Field2
C123 into Field1 .... 3 into Field2

Where do I start?
thanks!


You have chosen the comma as a delimiter in your example, so split()
breaks the string into an array wherever it sees a comma.

If you are actually inputting content like this:

A123,1
B123,2
C123,3

then the line breaks are what delimit your values. Your code should be
like this:

arrName = Split(Request.Form("TextArea"),chr(13))

Then you need to replace the commas with spaces within your for... next
loop:

For i = 0 To UBound(arrName)
Response.Write "ID: " & replace(arrName(i),","," ") & "<br>"
Next

By the way - you should define the collection in the Request Object you
want to reference (eg Request.Form, Request.QueryString). If you
don't, ASP will search all the collections, starting with
ServerVariables, and that is an expensive process in terms of overhead.

--
Mike Brind


Thanks! I'm stuck on how to get the data into a table.
Do I need to name the elements first?
I took a shot that Replace(arrName(i),","," ") would give me the values.
Didn'twork.

<%
arrName = Split(Request.Form("TextArea"),chr(13))
%>
<%
Dim DataConn, SQL
Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open MM_STRING

For i = 0 To UBound(arrName)
SQL = "INSERT INTO xtest ([OrderNo], [Qty]) "
SQL = SQL & "VALUES ('" & Replace(arrName(i),","," ") & "') "
DataConn.Execute(SQL)

' Response.Write "ID: " & replace(arrName(i),","," ") & "<br>"
Next
%>
Mar 14 '06 #3

shank wrote:
"Mike Brind" <pa*******@hotmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...

shank wrote:
I have the below code found on an ASP site.

<%
arrName = Split(Request("TextArea"),",")
%>
<%
For i = LBound(arrName) To UBound(arrName)
Response.Write "ID: " & arrName(i) & "<br>"
Next
%>

I'm using a TextArea box to submit the following...
A123,1
B123,2
C123,3
Results are...
ID: A123
ID: 1 B123
ID: 2 C123
ID: 3
I expected something like...
A123 1
B123 2
C123 3
For the sake of understanding, why are the results like above?

In the end, I want to insert these values into a table.
A123 into Field1 .... 1 into Field2
B123 into Field1 .... 2 into Field2
C123 into Field1 .... 3 into Field2

Where do I start?
thanks!


You have chosen the comma as a delimiter in your example, so split()
breaks the string into an array wherever it sees a comma.

If you are actually inputting content like this:

A123,1
B123,2
C123,3

then the line breaks are what delimit your values. Your code should be
like this:

arrName = Split(Request.Form("TextArea"),chr(13))

Then you need to replace the commas with spaces within your for... next
loop:

For i = 0 To UBound(arrName)
Response.Write "ID: " & replace(arrName(i),","," ") & "<br>"
Next

By the way - you should define the collection in the Request Object you
want to reference (eg Request.Form, Request.QueryString). If you
don't, ASP will search all the collections, starting with
ServerVariables, and that is an expensive process in terms of overhead.

--
Mike Brind


Thanks! I'm stuck on how to get the data into a table.
Do I need to name the elements first?
I took a shot that Replace(arrName(i),","," ") would give me the values.
Didn'twork.

<%
arrName = Split(Request.Form("TextArea"),chr(13))
%>
<%
Dim DataConn, SQL
Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open MM_STRING

For i = 0 To UBound(arrName)
SQL = "INSERT INTO xtest ([OrderNo], [Qty]) "
SQL = SQL & "VALUES ('" & Replace(arrName(i),","," ") & "') "
DataConn.Execute(SQL)

' Response.Write "ID: " & replace(arrName(i),","," ") & "<br>"
Next
%>


First off, I got the order that ASP reads the Request Object
collections wrong - it starts off with QueryString, then Form, then
Cookies, followed by ClientCertificate and finally ServerVariables. If
you misspell the name - and it doesn't appear anywhere, it will search
all collections. If you have two items with the same name but in
different collections, it will pick the one that occurs first.

Second, I presume fron the above that A123 1 represents two pieces of
data - A123 being the order number and 1 being the quantity?

If this is the case, you need to do a further split in arrName(i) with
the space as a delimiter to create two separate values prior to
inserting your data.

For i = 0 To UBound(arrName)
myvalues = split(arrName(i),",")
SQL = "INSERT INTO xtest ([OrderNo], [Qty]) "
SQL = SQL & "VALUES ('" & myvalue(0) & "'," & myvalue(1) & ")"
'assuming Qty is a numeric field, and OrderNo is text.
DataConn.Execute(SQL)

Your approach is fraught with danger. You can't guarantee that users
will input data in the format you want. I would recommend separate
form fields for each order and quantity, and server-side validation of
the values you receive.

Also, dynamic sql has its own dangers. If you are using google groups,
do a search for saved parameter queries in this group for some very
useful advice.

--
Mike Brind

Mar 15 '06 #4

"Mike Brind" <pa*******@hotmail.com> wrote in message
news:11**********************@j52g2000cwj.googlegr oups.com...

shank wrote:
"Mike Brind" <pa*******@hotmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
>
> shank wrote:
>> I have the below code found on an ASP site.
>>
>> <%
>> arrName = Split(Request("TextArea"),",")
>> %>
>> <%
>> For i = LBound(arrName) To UBound(arrName)
>> Response.Write "ID: " & arrName(i) & "<br>"
>> Next
>> %>
>>
>> I'm using a TextArea box to submit the following...
>> A123,1
>> B123,2
>> C123,3
>> Results are...
>> ID: A123
>> ID: 1 B123
>> ID: 2 C123
>> ID: 3
>> I expected something like...
>> A123 1
>> B123 2
>> C123 3
>> For the sake of understanding, why are the results like above?
>>
>> In the end, I want to insert these values into a table.
>> A123 into Field1 .... 1 into Field2
>> B123 into Field1 .... 2 into Field2
>> C123 into Field1 .... 3 into Field2
>>
>> Where do I start?
>> thanks!
>
> You have chosen the comma as a delimiter in your example, so split()
> breaks the string into an array wherever it sees a comma.
>
> If you are actually inputting content like this:
>
> A123,1
> B123,2
> C123,3
>
> then the line breaks are what delimit your values. Your code should be
> like this:
>
> arrName = Split(Request.Form("TextArea"),chr(13))
>
> Then you need to replace the commas with spaces within your for... next
> loop:
>
> For i = 0 To UBound(arrName)
> Response.Write "ID: " & replace(arrName(i),","," ") & "<br>"
> Next
>
> By the way - you should define the collection in the Request Object you
> want to reference (eg Request.Form, Request.QueryString). If you
> don't, ASP will search all the collections, starting with
> ServerVariables, and that is an expensive process in terms of overhead.
>
> --
> Mike Brind


Thanks! I'm stuck on how to get the data into a table.
Do I need to name the elements first?
I took a shot that Replace(arrName(i),","," ") would give me the values.
Didn'twork.

<%
arrName = Split(Request.Form("TextArea"),chr(13))
%>
<%
Dim DataConn, SQL
Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open MM_STRING

For i = 0 To UBound(arrName)
SQL = "INSERT INTO xtest ([OrderNo], [Qty]) "
SQL = SQL & "VALUES ('" & Replace(arrName(i),","," ") & "') "
DataConn.Execute(SQL)

' Response.Write "ID: " & replace(arrName(i),","," ") & "<br>"
Next
%>


First off, I got the order that ASP reads the Request Object
collections wrong - it starts off with QueryString, then Form, then
Cookies, followed by ClientCertificate and finally ServerVariables. If
you misspell the name - and it doesn't appear anywhere, it will search
all collections. If you have two items with the same name but in
different collections, it will pick the one that occurs first.

Second, I presume fron the above that A123 1 represents two pieces of
data - A123 being the order number and 1 being the quantity?

If this is the case, you need to do a further split in arrName(i) with
the space as a delimiter to create two separate values prior to
inserting your data.

For i = 0 To UBound(arrName)
myvalues = split(arrName(i),",")
SQL = "INSERT INTO xtest ([OrderNo], [Qty]) "
SQL = SQL & "VALUES ('" & myvalue(0) & "'," & myvalue(1) & ")"
'assuming Qty is a numeric field, and OrderNo is text.
DataConn.Execute(SQL)

Your approach is fraught with danger. You can't guarantee that users
will input data in the format you want. I would recommend separate
form fields for each order and quantity, and server-side validation of
the values you receive.

Also, dynamic sql has its own dangers. If you are using google groups,
do a search for saved parameter queries in this group for some very
useful advice.

--
Mike Brind


I created the following solution from code I found in a forum. It works. I
understand the issues with the dynamic SQL and whatever data the user may
submit. I need a solution where a user can just dump a huge list (hundreds)
of data with Item#s and quantities. It's a convenience thing. They will
generate the list on their end, then cut-n-paste into our site for
processing. The only smarter ways I'm aware of are not as convenient? Please
offer an alternative if you have one.

<%
varTextArea =
Replace(Replace(Replace(Request.Form("TextArea"),C hr(13),","),"
",""),Chr(10),"")
arrName = Split(varTextArea,",")
%>
<%
Dim DataConn, SQL
Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open MM_JSK_STRING

For i = 0 To UBound(arrName) Step 2
SQL = "INSERT INTO xtest ([OrderNo],[Qty]) "
SQL = SQL & "VALUES ('" & arrName(i) & "','" & arrName(i+1) & "') "
DataConn.Execute(SQL)
Next
%>
Mar 15 '06 #5

shank wrote:
"Mike Brind" <pa*******@hotmail.com> wrote in message
news:11**********************@j52g2000cwj.googlegr oups.com...

shank wrote:
"Mike Brind" <pa*******@hotmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
>
> shank wrote:
>> I have the below code found on an ASP site.
>>
>> <%
>> arrName = Split(Request("TextArea"),",")
>> %>
>> <%
>> For i = LBound(arrName) To UBound(arrName)
>> Response.Write "ID: " & arrName(i) & "<br>"
>> Next
>> %>
>>
>> I'm using a TextArea box to submit the following...
>> A123,1
>> B123,2
>> C123,3
>> Results are...
>> ID: A123
>> ID: 1 B123
>> ID: 2 C123
>> ID: 3
>> I expected something like...
>> A123 1
>> B123 2
>> C123 3
>> For the sake of understanding, why are the results like above?
>>
>> In the end, I want to insert these values into a table.
>> A123 into Field1 .... 1 into Field2
>> B123 into Field1 .... 2 into Field2
>> C123 into Field1 .... 3 into Field2
>>
>> Where do I start?
>> thanks!
>
> You have chosen the comma as a delimiter in your example, so split()
> breaks the string into an array wherever it sees a comma.
>
> If you are actually inputting content like this:
>
> A123,1
> B123,2
> C123,3
>
> then the line breaks are what delimit your values. Your code should be
> like this:
>
> arrName = Split(Request.Form("TextArea"),chr(13))
>
> Then you need to replace the commas with spaces within your for... next
> loop:
>
> For i = 0 To UBound(arrName)
> Response.Write "ID: " & replace(arrName(i),","," ") & "<br>"
> Next
>
> By the way - you should define the collection in the Request Object you
> want to reference (eg Request.Form, Request.QueryString). If you
> don't, ASP will search all the collections, starting with
> ServerVariables, and that is an expensive process in terms of overhead.
>
> --
> Mike Brind

Thanks! I'm stuck on how to get the data into a table.
Do I need to name the elements first?
I took a shot that Replace(arrName(i),","," ") would give me the values.
Didn'twork.

<%
arrName = Split(Request.Form("TextArea"),chr(13))
%>
<%
Dim DataConn, SQL
Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open MM_STRING

For i = 0 To UBound(arrName)
SQL = "INSERT INTO xtest ([OrderNo], [Qty]) "
SQL = SQL & "VALUES ('" & Replace(arrName(i),","," ") & "') "
DataConn.Execute(SQL)

' Response.Write "ID: " & replace(arrName(i),","," ") & "<br>"
Next
%>


First off, I got the order that ASP reads the Request Object
collections wrong - it starts off with QueryString, then Form, then
Cookies, followed by ClientCertificate and finally ServerVariables. If
you misspell the name - and it doesn't appear anywhere, it will search
all collections. If you have two items with the same name but in
different collections, it will pick the one that occurs first.

Second, I presume fron the above that A123 1 represents two pieces of
data - A123 being the order number and 1 being the quantity?

If this is the case, you need to do a further split in arrName(i) with
the space as a delimiter to create two separate values prior to
inserting your data.

For i = 0 To UBound(arrName)
myvalues = split(arrName(i),",")
SQL = "INSERT INTO xtest ([OrderNo], [Qty]) "
SQL = SQL & "VALUES ('" & myvalue(0) & "'," & myvalue(1) & ")"
'assuming Qty is a numeric field, and OrderNo is text.
DataConn.Execute(SQL)

Your approach is fraught with danger. You can't guarantee that users
will input data in the format you want. I would recommend separate
form fields for each order and quantity, and server-side validation of
the values you receive.

Also, dynamic sql has its own dangers. If you are using google groups,
do a search for saved parameter queries in this group for some very
useful advice.

--
Mike Brind


I created the following solution from code I found in a forum. It works. I
understand the issues with the dynamic SQL and whatever data the user may
submit. I need a solution where a user can just dump a huge list (hundreds)
of data with Item#s and quantities. It's a convenience thing. They will
generate the list on their end, then cut-n-paste into our site for
processing. The only smarter ways I'm aware of are not as convenient? Please
offer an alternative if you have one.

<%
varTextArea =
Replace(Replace(Replace(Request.Form("TextArea"),C hr(13),","),"
",""),Chr(10),"")
arrName = Split(varTextArea,",")
%>
<%
Dim DataConn, SQL
Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open MM_JSK_STRING

For i = 0 To UBound(arrName) Step 2
SQL = "INSERT INTO xtest ([OrderNo],[Qty]) "
SQL = SQL & "VALUES ('" & arrName(i) & "','" & arrName(i+1) & "') "
DataConn.Execute(SQL)
Next
%>

Try this:

<%
varTextArea = Split(Request.Form("TextArea"),Chr(13))
'This operation gives you an array of single values, so
'varTextArea(0) is A123,1
'varTextArea(1) is B123,2 etc

Dim DataConn, SQL
Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open MM_JSK_STRING

'Now you need to separate the Order No from the Qty for each of the
array values
'The comma is the delimiter. Since you have to do this for each of the
values
'you have to do it within the loop

For i = 0 To UBound(varTextArea)
arrName = Split(varTextArea(i),",")
SQL = "INSERT INTO xtest ([OrderNo],[Qty]) "
SQL = SQL & "VALUES ('" & arrName(0) & "','" & arrName(1) & "') "
DataConn.Execute(SQL)
Next
%>

HTH

--
Mike Brind

Mar 15 '06 #6
Mike Brind wrote:

Dim DataConn, SQL
Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open MM_JSK_STRING

'Now you need to separate the Order No from the Qty for each of the
array values
'The comma is the delimiter. Since you have to do this for each of
the values
'you have to do it within the loop

For i = 0 To UBound(varTextArea)
arrName = Split(varTextArea(i),",")
SQL = "INSERT INTO xtest ([OrderNo],[Qty]) "
SQL = SQL & "VALUES ('" & arrName(0) & "','" & arrName(1) & "') "
DataConn.Execute(SQL)
Next
%>

Better yet:
Dim DataConn, SQL, cmd, ,ordno,qtyarParms
SQL = "INSERT INTO xtest ([OrderNo],[Qty]) "
SQL = SQL & "VALUES (?,?) "
Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open MM_JSK_STRING
Set cmd=createobject("adodb.command")
with cmd
.commandtext=SQL
.commandtype=1 'adcmdtext
set .acriveconnection=dataconn
end with
'Now you need to separate the Order No from the Qty for each of the
array values
'The comma is the delimiter. Since you have to do this for each of the
values
'you have to do it within the loop

For i = 0 To UBound(varTextArea)
arrName = Split(varTextArea(i),",")
ordno=arrName(0)
qty=arrName(1)
'validate the data here, then
arparms=array(ordno,qty)
cmd.Execute ,arparms,128 'adExecuteNoRecords
Next
%>

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Mar 15 '06 #7

Bob Barrows [MVP] wrote:
Mike Brind wrote:

Dim DataConn, SQL
Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open MM_JSK_STRING

'Now you need to separate the Order No from the Qty for each of the
array values
'The comma is the delimiter. Since you have to do this for each of
the values
'you have to do it within the loop

For i = 0 To UBound(varTextArea)
arrName = Split(varTextArea(i),",")
SQL = "INSERT INTO xtest ([OrderNo],[Qty]) "
SQL = SQL & "VALUES ('" & arrName(0) & "','" & arrName(1) & "') "
DataConn.Execute(SQL)
Next
%>
Better yet:
Dim DataConn, SQL, cmd, ,ordno,qtyarParms
SQL = "INSERT INTO xtest ([OrderNo],[Qty]) "
SQL = SQL & "VALUES (?,?) "
Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open MM_JSK_STRING
Set cmd=createobject("adodb.command")
with cmd
.commandtext=SQL
.commandtype=1 'adcmdtext
set .acriveconnection=dataconn


**NOTE**
The above line should be set .activeconnection=dataconn
end with
'Now you need to separate the Order No from the Qty for each of the
array values
'The comma is the delimiter. Since you have to do this for each of the
values
'you have to do it within the loop

For i = 0 To UBound(varTextArea)
arrName = Split(varTextArea(i),",")
ordno=arrName(0)
qty=arrName(1)
'validate the data here, then
arparms=array(ordno,qty)
cmd.Execute ,arparms,128 'adExecuteNoRecords
Next
%>


Thanks Bob.

To shank: Now you have no excuse NOT to use parameters instead of
dynamic sql :-)

--
Mike Brind

Mar 15 '06 #8
> Better yet:
Dim DataConn, SQL, cmd, ,ordno,qtyarParms
SQL = "INSERT INTO xtest ([OrderNo],[Qty]) "
SQL = SQL & "VALUES (?,?) "
Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open MM_JSK_STRING
Set cmd=createobject("adodb.command")
with cmd
.commandtext=SQL
.commandtype=1 'adcmdtext
set .acriveconnection=dataconn
end with
'Now you need to separate the Order No from the Qty for each of the
array values
'The comma is the delimiter. Since you have to do this for each of the
values
'you have to do it within the loop

For i = 0 To UBound(varTextArea)
arrName = Split(varTextArea(i),",")
ordno=arrName(0)
qty=arrName(1)
'validate the data here, then
arparms=array(ordno,qty)
cmd.Execute ,arparms,128 'adExecuteNoRecords
Next
%>

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

- - - - - - - - - - - - - - - - - - - - - -
The below does not insert any data. I changed what I thought was a few typos
with no luck. It lookd kind of backwards to me. Shouldn't the variables be
filled "before" the SQL statement runs?
thanks!
<%
Dim DataConn,SQL,cmd,orderno,qty,arParms
SQL = "INSERT INTO xtest ([OrderNo],[Qty]) "
SQL = SQL & "VALUES (?,?) " '<-- I
thought this was a typo
'SQL = SQL & "VALUES (" & orderno & "," & qty & ") " '<-- didn't work
either
Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open MM_JSK_STRING
Set cmd=createobject("adodb.command")
with cmd
.commandtext=SQL
.commandtype=1 'adcmdtext
set .activeconnection=DataConn
end with

For i = 0 To UBound(varTextArea)
arrName = Split(varTextArea(i),",")
orderno=arrName(0)
qty=arrName(1)
'validate the data here, then
arParms=array(orderno,qty)
cmd.Execute ,arParms,128 'adExecuteNoRecords
Next
%>
Mar 15 '06 #9
shank wrote:
The below does not insert any data. I changed what I thought was a
few typos with no luck. It lookd kind of backwards to me. Shouldn't
the variables be filled "before" the SQL statement runs?

:-)
Assigning a string to a variable does not run the sql statement.

You "fixed" what was required to make it work.

The question marks are called "parameter markers", or more technically "odbc
parameter markers". They are what allows the Command object to pass the
parameter values into the sql statement.. Change it back to what I posted!

If nothing is getting inserted, then it is likely that your loop is not
running. Put in some response.write statements to verify this:

response.write "About to start looping.<br>" For i = 0 To UBound(varTextArea)
arrName = Split(varTextArea(i),",")
orderno=arrName(0)
qty=arrName(1)
'validate the data here, then
arParms=array(orderno,qty) response.write "About to insert " & ordno & " and " & _
qty & " into the database table.<br>" cmd.Execute ,arParms,128 'adExecuteNoRecords
Next
%>


Let us know the result.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Mar 15 '06 #10

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:uN*************@TK2MSFTNGP10.phx.gbl...
shank wrote:
The below does not insert any data. I changed what I thought was a
few typos with no luck. It lookd kind of backwards to me. Shouldn't
the variables be filled "before" the SQL statement runs?

:-)
Assigning a string to a variable does not run the sql statement.

You "fixed" what was required to make it work.

The question marks are called "parameter markers", or more technically
"odbc
parameter markers". They are what allows the Command object to pass the
parameter values into the sql statement.. Change it back to what I posted!

If nothing is getting inserted, then it is likely that your loop is not
running. Put in some response.write statements to verify this:

response.write "About to start looping.<br>"
For i = 0 To UBound(varTextArea)
arrName = Split(varTextArea(i),",")
orderno=arrName(0)
qty=arrName(1)
'validate the data here, then
arParms=array(orderno,qty)

response.write "About to insert " & ordno & " and " & _
qty & " into the database table.<br>"
cmd.Execute ,arParms,128 'adExecuteNoRecords
Next
%>


Let us know the result.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
I found a couple statements that I missed and also 1 variable.
I'm submitting...
A123,1
B123,1
C123,1
D123,1
E123,1
F123,1
G123,1
This is returned to the screen...
About to start looping.
About to insert A123 and 1 into the database table.

And only 1 record is inserted. It's not looping through all records.
thanks
<%
varTextArea =
Replace(Replace(Replace(Request.Form("TextArea"),C hr(13),","),"
",""),Chr(10),"")
arrName = Split(varTextArea,",")

Dim DataConn,SQL,cmd,orderno,qty,arParms
SQL = "INSERT INTO xtest ([AffNo],[OrderNo],[Qty]) "
SQL = SQL & "VALUES ('" & Session("AffNo") & "',?,?) "
Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open MM_JSK_STRING
Set cmd=createobject("adodb.command")
with cmd
.commandtext=SQL
.commandtype=1 'adcmdtext
set .activeconnection=DataConn
end with

response.write "About to start looping.<br>"
For i = 0 To UBound(varTextArea)
arrName = Split(varTextArea(i),",")
orderno=arrName(0)
qty=arrName(1)
'validate the data here, then
arParms=array(orderno,qty)
response.write "About to insert " & orderno & " and " & _
qty & " into the database table.<br>"
cmd.Execute ,arParms,128 'adExecuteNoRecords
Next
%>
Mar 15 '06 #11
shank wrote:
- - - -
I found a couple statements that I missed and also 1 variable.
I'm submitting...
A123,1
B123,1
C123,1
D123,1
E123,1
F123,1
G123,1
This is returned to the screen...
About to start looping.
About to insert A123 and 1 into the database table.

And only 1 record is inserted. It's not looping through all records.
thanks


I was going to say that this means varTextArea is not an array, but if that
was the case, UBound(varTextArea) would throw an error, and the loop would
not even begin! Hmm, where does that variable become an array in your code
....?

Never mind ... it looks as if you need to split varTextArea on vbCrLf, loop
through that array, splitting the elements of that array on the "," and
processing the results of that split operation. Like this:

varTextArea =Split(Request.Form("TextArea"), vbCrLf)
Dim DataConn,SQL,cmd,orderno,qty,arParms
SQL = "INSERT INTO xtest ([AffNo],[OrderNo],[Qty]) "
SQL = SQL & "VALUES ('" & Session("AffNo") & "',?,?) "
Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open MM_JSK_STRING
Set cmd=createobject("adodb.command")
with cmd
.commandtext=SQL
.commandtype=1 'adcmdtext
set .activeconnection=DataConn
end with

response.write "About to start looping.<br>"
For i = 0 To UBound(varTextArea)
arrName = Split(varTextArea(i),",")
orderno=arrName(0)
qty=arrName(1)
'validate the data here, then
arParms=array(orderno,qty)
response.write "About to insert " & orderno & " and " & _
qty & " into the database table.<br>"
cmd.Execute ,arParms,128 'adExecuteNoRecords
Next

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Mar 15 '06 #12

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:Oa**************@TK2MSFTNGP10.phx.gbl...
shank wrote:
- - - -
I found a couple statements that I missed and also 1 variable.
I'm submitting...
A123,1
B123,1
C123,1
D123,1
E123,1
F123,1
G123,1
This is returned to the screen...
About to start looping.
About to insert A123 and 1 into the database table.

And only 1 record is inserted. It's not looping through all records.
thanks


I was going to say that this means varTextArea is not an array, but if
that
was the case, UBound(varTextArea) would throw an error, and the loop would
not even begin! Hmm, where does that variable become an array in your code
...?

Never mind ... it looks as if you need to split varTextArea on vbCrLf,
loop
through that array, splitting the elements of that array on the "," and
processing the results of that split operation. Like this:

varTextArea =Split(Request.Form("TextArea"), vbCrLf)
Dim DataConn,SQL,cmd,orderno,qty,arParms
SQL = "INSERT INTO xtest ([AffNo],[OrderNo],[Qty]) "
SQL = SQL & "VALUES ('" & Session("AffNo") & "',?,?) "
Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open MM_JSK_STRING
Set cmd=createobject("adodb.command")
with cmd
.commandtext=SQL
.commandtype=1 'adcmdtext
set .activeconnection=DataConn
end with

response.write "About to start looping.<br>"
For i = 0 To UBound(varTextArea)
arrName = Split(varTextArea(i),",")
orderno=arrName(0)
qty=arrName(1)
'validate the data here, then
arParms=array(orderno,qty)
response.write "About to insert " & orderno & " and " & _
qty & " into the database table.<br>"
cmd.Execute ,arParms,128 'adExecuteNoRecords
Next

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - -
Shazam! That worked! Thanks!

Now I need to move onto the next phase.
If a record exists WHERE [AffNo] = Session("AffNo") AND [OrderNo] = orderno
I need to UPDATE [Qty] = [Qty] + 1
How do I do this?
I had a vague clue using the previous dynamic SQL.
But he above param code is a new issue.
thanks!
Mar 15 '06 #13
Bob Barrows [MVP] wrote:
SQL = "INSERT INTO xtest ([AffNo],[OrderNo],[Qty]) "
SQL = SQL & "VALUES ('" & Session("AffNo") & "',?,?) "
Oh wait! You added something.

Look. You have got to stop thinking "concatenate" when inserting values into
your sql statements. The above line should read:
SQL = SQL & "VALUES (?,?,?) "

And this line: arParms=array(orderno,qty)


needs to become:
arParms=array(Session("AffNo"),orderno,qty)

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Mar 15 '06 #14
shank wrote:
Shazam! That worked! Thanks!

Now I need to move onto the next phase.
If a record exists WHERE [AffNo] = Session("AffNo") AND [OrderNo] =
orderno I need to UPDATE [Qty] = [Qty] + 1
How do I do this?
I had a vague clue using the previous dynamic SQL.
But he above param code is a new issue.
thanks!


SQL="UPDATE xtest SET [Qty] = [Qty] + 1 " & _
"WHERE [AffNo] = ? AND [OrderNo] = ?"
cmd.CommandText=SQL
arParms=array(Session("AffNo"),orderno)

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Mar 15 '06 #15

shank wrote:
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:uN*************@TK2MSFTNGP10.phx.gbl...
shank wrote:
The below does not insert any data. I changed what I thought was a
few typos with no luck. It lookd kind of backwards to me. Shouldn't
the variables be filled "before" the SQL statement runs?

:-)
Assigning a string to a variable does not run the sql statement.

You "fixed" what was required to make it work.

The question marks are called "parameter markers", or more technically
"odbc
parameter markers". They are what allows the Command object to pass the
parameter values into the sql statement.. Change it back to what I posted!

If nothing is getting inserted, then it is likely that your loop is not
running. Put in some response.write statements to verify this:

response.write "About to start looping.<br>"
For i = 0 To UBound(varTextArea)
arrName = Split(varTextArea(i),",")
orderno=arrName(0)
qty=arrName(1)
'validate the data here, then
arParms=array(orderno,qty)

response.write "About to insert " & ordno & " and " & _
qty & " into the database table.<br>"
cmd.Execute ,arParms,128 'adExecuteNoRecords
Next
%>


Let us know the result.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
I found a couple statements that I missed and also 1 variable.
I'm submitting...
A123,1
B123,1
C123,1
D123,1
E123,1
F123,1
G123,1
This is returned to the screen...
About to start looping.
About to insert A123 and 1 into the database table.

And only 1 record is inserted. It's not looping through all records.
thanks
<%
varTextArea =
Replace(Replace(Replace(Request.Form("TextArea"),C hr(13),","),"
",""),Chr(10),"")


(1)I don't know why you changed it back to this ^^^^^^
arrName = Split(varTextArea,",")
(2) ^^^^^I don't know why you took this operation back outside fo the
loop

Dim DataConn,SQL,cmd,orderno,qty,arParms
SQL = "INSERT INTO xtest ([AffNo],[OrderNo],[Qty]) "
SQL = SQL & "VALUES ('" & Session("AffNo") & "',?,?) "
Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open MM_JSK_STRING
Set cmd=createobject("adodb.command")
with cmd
.commandtext=SQL
.commandtype=1 'adcmdtext
set .activeconnection=DataConn
end with

response.write "About to start looping.<br>"
For i = 0 To UBound(varTextArea)
arrName = Split(varTextArea(i),",")
(2) ^^^^ This is where I put it - and you kept it there as well
orderno=arrName(0)
qty=arrName(1)
'validate the data here, then
arParms=array(orderno,qty)
response.write "About to insert " & orderno & " and " & _
qty & " into the database table.<br>"
cmd.Execute ,arParms,128 'adExecuteNoRecords
Next
%>


(1) The operation you changed back to a replace was the first split
that turned each line into an array element in the code I posted last
night.

It looked for the line break - chr(13) (or vbcrlf, as Bob as posted),
and broke the input apart on that character, giving you an array which
holds each line in the text area as an element.

Each element consists of a string, which contains some text on the
left, a comma and some text on the right. This is what needs to be
split again, one element at a time so that you can insert each part
into your database. So this time, within the loop, the split needed to
be done on the comma - arrName = split(varTextArea,","), which gives
two elemtns in a new array (which is called arrName). You reference
these according to their ordinal position, bearring in mind that arrays
resulting from the split() function start from 0, so arrName(0) is the
order number, and arrName(1) is the quantity.

Bob's put the functions back where they should be, so hopefully his
latest offer will work for you. I can't see any reason why it
shouldn't, but then again, that depends on how much you want to dabble
with the order in which things are done ;-)

--
Mike Brind

Mar 15 '06 #16

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:OU**************@tk2msftngp13.phx.gbl...
shank wrote:
Shazam! That worked! Thanks!

Now I need to move onto the next phase.
If a record exists WHERE [AffNo] = Session("AffNo") AND [OrderNo] =
orderno I need to UPDATE [Qty] = [Qty] + 1
How do I do this?
I had a vague clue using the previous dynamic SQL.
But he above param code is a new issue.
thanks!


SQL="UPDATE xtest SET [Qty] = [Qty] + 1 " & _
"WHERE [AffNo] = ? AND [OrderNo] = ?"
cmd.CommandText=SQL
arParms=array(Session("AffNo"),orderno)

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

--------------------------------------------------------------
I've evolved to the following. I can insert, but it will not update if a
similar records exists. I'm assuming I need to do a select to test each
record, then determine if it's an INSERT or UPDATE statement. Please indulge
me a bit longer! I get no errors. Only inserts and no updates.
thanks

<%
varTextArea =Split(Request.Form("TextArea"), vbCrLf)

Dim DataConn,SQL,cmd,orderno,qty,arParms

DataConn.Open MM_JSK_STRING
s = "SELECT [AffNo],[OrderNo],[Qty] FROM xTest WHERE WHERE [AffNo] = ? AND
[OrderNo] = ?"
Set rs = DataConn.Execute(s)

If (rs.EOF) Then
SQL = "INSERT INTO xtest ([AffNo],[OrderNo],[Qty]) "
SQL = SQL & "VALUES (?,?,?) "
Else
SQL="UPDATE xtest SET [Qty] = [Qty] + 1 " & _
"WHERE [AffNo] = ? AND [OrderNo] = ?"
cmd.CommandText=SQL
arParms=array(Session("AffNo"),orderno)
End If

Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open MM_JSK_STRING
Set cmd=createobject("adodb.command")
with cmd
.commandtext=SQL
.commandtype=1 'adcmdtext
set .activeconnection=DataConn
end with

response.write "About to start looping.<br>"
For i = 0 To UBound(varTextArea)
arrName = Split(varTextArea(i),",")
orderno=arrName(0)
qty=arrName(1)
'validate the data here, then
arParms=array(Session("AffNo"),orderno,qty)
response.write "About to insert " & orderno & " and " & _
qty & " into the database table.<br>"
cmd.Execute ,arParms,128 'adExecuteNoRecords
Next
%>
Mar 15 '06 #17
shank wrote:
I've evolved to the following. I can insert, but it will not update
if a similar records exists. I'm assuming I need to do a select to
test each record, then determine if it's an INSERT or UPDATE
statement. Please indulge me a bit longer! I get no errors. Only
inserts and no updates.
thanks

Give me some clue about what you really want to have happen here. :-)

I need to know, step-by-step, data element by data element, what you expect
this code to do.

I can't tell from reading the code which is probably in error.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Mar 15 '06 #18

shank wrote:

<snip>
I've evolved to the following. I can insert, but it will not update if a
similar records exists. I'm assuming I need to do a select to test each
record, then determine if it's an INSERT or UPDATE statement. Please indulge
me a bit longer! I get no errors. Only inserts and no updates.
thanks

<%
varTextArea =Split(Request.Form("TextArea"), vbCrLf)

Dim DataConn,SQL,cmd,orderno,qty,arParms

DataConn.Open MM_JSK_STRING
s = "SELECT [AffNo],[OrderNo],[Qty] FROM xTest WHERE WHERE [AffNo] = ? AND
[OrderNo] = ?"
Set rs = DataConn.Execute(s)

If (rs.EOF) Then
SQL = "INSERT INTO xtest ([AffNo],[OrderNo],[Qty]) "
SQL = SQL & "VALUES (?,?,?) "
Else
SQL="UPDATE xtest SET [Qty] = [Qty] + 1 " & _
"WHERE [AffNo] = ? AND [OrderNo] = ?"
cmd.CommandText=SQL
arParms=array(Session("AffNo"),orderno)
End If

Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open MM_JSK_STRING
Set cmd=createobject("adodb.command")
with cmd
.commandtext=SQL
.commandtype=1 'adcmdtext
set .activeconnection=DataConn
end with

response.write "About to start looping.<br>"
For i = 0 To UBound(varTextArea)
arrName = Split(varTextArea(i),",")
orderno=arrName(0)
qty=arrName(1)
'validate the data here, then
arParms=array(Session("AffNo"),orderno,qty)
response.write "About to insert " & orderno & " and " & _
qty & " into the database table.<br>"
cmd.Execute ,arParms,128 'adExecuteNoRecords
Next
%>


According to the above code, and your previous posts, what you are
trying to do is to take a series of order numbers with associated
quantities, then checking to see if identical value pairings already
exist in the database. If they do not, you insert a new record. If
they do, you increment the quantity associated with the order number by
1.

Your code needs to be tweaked a bit more to achieve that, but if that
is what you ARE trying to achieve, it makes little sense, for a couple
of reasons.

First, in most applications something like an order number is usually
unique, and can't/shouldn't be used again. Does your application allow
re-use of existing order numbers?

Second, you've hardcoded your update routine to increment the quantity
by 1. The example you posted originally suggested that the quantities
can be any number. If you are re-using existing order numbers,
shouldn't you be incrementing by the value of the new quantity?

--
Mike Brind

Second

Mar 15 '06 #19

"Mike Brind" <pa*******@hotmail.com> wrote in message
news:11*********************@i39g2000cwa.googlegro ups.com...

shank wrote:

<snip>
I've evolved to the following. I can insert, but it will not update if a
similar records exists. I'm assuming I need to do a select to test each
record, then determine if it's an INSERT or UPDATE statement. Please
indulge
me a bit longer! I get no errors. Only inserts and no updates.
thanks

<%
varTextArea =Split(Request.Form("TextArea"), vbCrLf)

Dim DataConn,SQL,cmd,orderno,qty,arParms

DataConn.Open MM_JSK_STRING
s = "SELECT [AffNo],[OrderNo],[Qty] FROM xTest WHERE WHERE [AffNo] = ?
AND
[OrderNo] = ?"
Set rs = DataConn.Execute(s)

If (rs.EOF) Then
SQL = "INSERT INTO xtest ([AffNo],[OrderNo],[Qty]) "
SQL = SQL & "VALUES (?,?,?) "
Else
SQL="UPDATE xtest SET [Qty] = [Qty] + 1 " & _
"WHERE [AffNo] = ? AND [OrderNo] = ?"
cmd.CommandText=SQL
arParms=array(Session("AffNo"),orderno)
End If

Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open MM_JSK_STRING
Set cmd=createobject("adodb.command")
with cmd
.commandtext=SQL
.commandtype=1 'adcmdtext
set .activeconnection=DataConn
end with

response.write "About to start looping.<br>"
For i = 0 To UBound(varTextArea)
arrName = Split(varTextArea(i),",")
orderno=arrName(0)
qty=arrName(1)
'validate the data here, then
arParms=array(Session("AffNo"),orderno,qty)
response.write "About to insert " & orderno & " and " & _
qty & " into the database table.<br>"
cmd.Execute ,arParms,128 'adExecuteNoRecords
Next
%>


According to the above code, and your previous posts, what you are
trying to do is to take a series of order numbers with associated
quantities, then checking to see if identical value pairings already
exist in the database. If they do not, you insert a new record. If
they do, you increment the quantity associated with the order number by
1.

Your code needs to be tweaked a bit more to achieve that, but if that
is what you ARE trying to achieve, it makes little sense, for a couple
of reasons.

First, in most applications something like an order number is usually
unique, and can't/shouldn't be used again. Does your application allow
re-use of existing order numbers?

Second, you've hardcoded your update routine to increment the quantity
by 1. The example you posted originally suggested that the quantities
can be any number. If you are re-using existing order numbers,
shouldn't you be incrementing by the value of the new quantity?

--
Mike Brind

-------------------------------
what you are trying to do is to take a series of order numbers with
associated quantities, then checking to see if identical value pairings
already exist in the database. If they do not, you insert a new record.
If they do, you increment the quantity associated with the order number by
1<<
That is correct!
most applications something like an order number is usually unique, and
can't/shouldn't be used again<<
I'm trying to allow users that know our order system to cut-n-paste large
lists of order#s and quantities for their inventory updates. The AffNo is
their account#. I'm anticipating users creating lists ,then coming back to
them day after day and adding to the list.
Second, you've hardcoded your update routine to increment the quantity by
1.<<


You're right! That was an oversight. The Qty should be increased by the new
qty submitted.

thanks!
Mar 15 '06 #20

shank wrote:
"Mike Brind" <pa*******@hotmail.com> wrote in message
news:11*********************@i39g2000cwa.googlegro ups.com...

shank wrote:

<snip>
I've evolved to the following. I can insert, but it will not update if a
similar records exists. I'm assuming I need to do a select to test each
record, then determine if it's an INSERT or UPDATE statement. Please
indulge
me a bit longer! I get no errors. Only inserts and no updates.
thanks

<%
varTextArea =Split(Request.Form("TextArea"), vbCrLf)

Dim DataConn,SQL,cmd,orderno,qty,arParms

DataConn.Open MM_JSK_STRING
s = "SELECT [AffNo],[OrderNo],[Qty] FROM xTest WHERE WHERE [AffNo] = ?
AND
[OrderNo] = ?"
Set rs = DataConn.Execute(s)

If (rs.EOF) Then
SQL = "INSERT INTO xtest ([AffNo],[OrderNo],[Qty]) "
SQL = SQL & "VALUES (?,?,?) "
Else
SQL="UPDATE xtest SET [Qty] = [Qty] + 1 " & _
"WHERE [AffNo] = ? AND [OrderNo] = ?"
cmd.CommandText=SQL
arParms=array(Session("AffNo"),orderno)
End If

Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open MM_JSK_STRING
Set cmd=createobject("adodb.command")
with cmd
.commandtext=SQL
.commandtype=1 'adcmdtext
set .activeconnection=DataConn
end with

response.write "About to start looping.<br>"
For i = 0 To UBound(varTextArea)
arrName = Split(varTextArea(i),",")
orderno=arrName(0)
qty=arrName(1)
'validate the data here, then
arParms=array(Session("AffNo"),orderno,qty)
response.write "About to insert " & orderno & " and " & _
qty & " into the database table.<br>"
cmd.Execute ,arParms,128 'adExecuteNoRecords
Next
%>


According to the above code, and your previous posts, what you are
trying to do is to take a series of order numbers with associated
quantities, then checking to see if identical value pairings already
exist in the database. If they do not, you insert a new record. If
they do, you increment the quantity associated with the order number by
1.


Possible correction - I would guess that you are not looking for
identical entries on both order number AND quantity, you are just
looking to see if the order number already exists in the database
before performing an Update on the quantity for that order number,
rather than Inserting a complete new row. Is that correct?

--
Mike Brind

Mar 15 '06 #21

"Mike Brind" <pa*******@hotmail.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...

shank wrote:
"Mike Brind" <pa*******@hotmail.com> wrote in message
news:11*********************@i39g2000cwa.googlegro ups.com...
>
> shank wrote:
>
> <snip>
>
>> I've evolved to the following. I can insert, but it will not update if
>> a
>> similar records exists. I'm assuming I need to do a select to test
>> each
>> record, then determine if it's an INSERT or UPDATE statement. Please
>> indulge
>> me a bit longer! I get no errors. Only inserts and no updates.
>> thanks
>>
>> <%
>> varTextArea =Split(Request.Form("TextArea"), vbCrLf)
>>
>> Dim DataConn,SQL,cmd,orderno,qty,arParms
>>
>> DataConn.Open MM_JSK_STRING
>> s = "SELECT [AffNo],[OrderNo],[Qty] FROM xTest WHERE WHERE [AffNo] = ?
>> AND
>> [OrderNo] = ?"
>> Set rs = DataConn.Execute(s)
>>
>> If (rs.EOF) Then
>> SQL = "INSERT INTO xtest ([AffNo],[OrderNo],[Qty]) "
>> SQL = SQL & "VALUES (?,?,?) "
>> Else
>> SQL="UPDATE xtest SET [Qty] = [Qty] + 1 " & _
>> "WHERE [AffNo] = ? AND [OrderNo] = ?"
>> cmd.CommandText=SQL
>> arParms=array(Session("AffNo"),orderno)
>> End If
>>
>> Set DataConn = Server.CreateObject("ADODB.Connection")
>> DataConn.Open MM_JSK_STRING
>> Set cmd=createobject("adodb.command")
>> with cmd
>> .commandtext=SQL
>> .commandtype=1 'adcmdtext
>> set .activeconnection=DataConn
>> end with
>>
>> response.write "About to start looping.<br>"
>> For i = 0 To UBound(varTextArea)
>> arrName = Split(varTextArea(i),",")
>> orderno=arrName(0)
>> qty=arrName(1)
>> 'validate the data here, then
>> arParms=array(Session("AffNo"),orderno,qty)
>> response.write "About to insert " & orderno & " and " & _
>> qty & " into the database table.<br>"
>> cmd.Execute ,arParms,128 'adExecuteNoRecords
>> Next
>> %>
>
> According to the above code, and your previous posts, what you are
> trying to do is to take a series of order numbers with associated
> quantities, then checking to see if identical value pairings already
> exist in the database. If they do not, you insert a new record. If
> they do, you increment the quantity associated with the order number by
> 1.
>


Possible correction - I would guess that you are not looking for
identical entries on both order number AND quantity, you are just
looking to see if the order number already exists in the database
before performing an Update on the quantity for that order number,
rather than Inserting a complete new row. Is that correct?

--
Mike Brind

--------------------------------
The match would be AffNo and OrderNo.
That criteria would define whether the record is inserted or updated.
It associates the product to the user ordering it.
There will be many users adding to the database, day after day.
thanks!
Mar 15 '06 #22

shank wrote:
"Mike Brind" <pa*******@hotmail.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...

shank wrote:
"Mike Brind" <pa*******@hotmail.com> wrote in message
news:11*********************@i39g2000cwa.googlegro ups.com...
>
> shank wrote:
>
> <snip>
>
>> I've evolved to the following. I can insert, but it will not update if
>> a
>> similar records exists. I'm assuming I need to do a select to test
>> each
>> record, then determine if it's an INSERT or UPDATE statement. Please
>> indulge
>> me a bit longer! I get no errors. Only inserts and no updates.
>> thanks
>>
>> <%
>> varTextArea =Split(Request.Form("TextArea"), vbCrLf)
>>
>> Dim DataConn,SQL,cmd,orderno,qty,arParms
>>
>> DataConn.Open MM_JSK_STRING
>> s = "SELECT [AffNo],[OrderNo],[Qty] FROM xTest WHERE WHERE [AffNo] = ?
>> AND
>> [OrderNo] = ?"
>> Set rs = DataConn.Execute(s)
>>
>> If (rs.EOF) Then
>> SQL = "INSERT INTO xtest ([AffNo],[OrderNo],[Qty]) "
>> SQL = SQL & "VALUES (?,?,?) "
>> Else
>> SQL="UPDATE xtest SET [Qty] = [Qty] + 1 " & _
>> "WHERE [AffNo] = ? AND [OrderNo] = ?"
>> cmd.CommandText=SQL
>> arParms=array(Session("AffNo"),orderno)
>> End If
>>
>> Set DataConn = Server.CreateObject("ADODB.Connection")
>> DataConn.Open MM_JSK_STRING
>> Set cmd=createobject("adodb.command")
>> with cmd
>> .commandtext=SQL
>> .commandtype=1 'adcmdtext
>> set .activeconnection=DataConn
>> end with
>>
>> response.write "About to start looping.<br>"
>> For i = 0 To UBound(varTextArea)
>> arrName = Split(varTextArea(i),",")
>> orderno=arrName(0)
>> qty=arrName(1)
>> 'validate the data here, then
>> arParms=array(Session("AffNo"),orderno,qty)
>> response.write "About to insert " & orderno & " and " & _
>> qty & " into the database table.<br>"
>> cmd.Execute ,arParms,128 'adExecuteNoRecords
>> Next
>> %>
>
> According to the above code, and your previous posts, what you are
> trying to do is to take a series of order numbers with associated
> quantities, then checking to see if identical value pairings already
> exist in the database. If they do not, you insert a new record. If
> they do, you increment the quantity associated with the order number by
> 1.
>


Possible correction - I would guess that you are not looking for
identical entries on both order number AND quantity, you are just
looking to see if the order number already exists in the database
before performing an Update on the quantity for that order number,
rather than Inserting a complete new row. Is that correct?

--
Mike Brind

--------------------------------
The match would be AffNo and OrderNo.
That criteria would define whether the record is inserted or updated.
It associates the product to the user ordering it.
There will be many users adding to the database, day after day.
thanks!

This should do it:

Dim DataConn,SQL,cmd,orderno,qty,arParms, varTextArea

Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open MM_JSK_STRING
Set cmd=createobject("adodb.command")
cmd.commandtype=1 'adcmdtext
set cmd.activeconnection=DataConn

varTextArea =Split(Request.Form("TextArea"), vbCrLf)

For i = 0 To UBound(varTextArea)
arrName = Split(varTextArea(i),",")
orderno=arrName(0)
qty=arrName(1)
'validate data
s = "SELECT [OrderNo],[Qty] FROM xTest WHERE " & _
"[AffNo] = ? AND [OrderNo] = ?"
arrParms=array(Session("AffNo"),orderno)
cmd.commandtext=s
Set rs = cmd.Execute(,arrParms)

If (rs.EOF) Then
SQL = "INSERT INTO xtest ([AffNo],[OrderNo],[Qty]) " & _
"VALUES ('" & Session("AffNo") & "',?,?) "
arParms=array(orderno,qty)
Else
SQL="UPDATE xtest SET [Qty] = [Qty] + " & qty & _
" WHERE [AffNo] = ? AND [OrderNo] = ?"
arParms=array(Session("AffNo"),orderno)
End If

cmd.commandtext=SQL
cmd.Execute ,arParms,128 'adExecuteNoRecords
rs.close : set rs = nothing
Next
'clean up

There's no data validation within this code, and others might find a
couple of ways to improve its efficiency etc.

--
Mike Brind

Mar 16 '06 #23

"Mike Brind" <pa*******@hotmail.com> wrote in message
news:11**********************@p10g2000cwp.googlegr oups.com...

shank wrote:
"Mike Brind" <pa*******@hotmail.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
>
> shank wrote:
>> "Mike Brind" <pa*******@hotmail.com> wrote in message
>> news:11*********************@i39g2000cwa.googlegro ups.com...
>> >
>> > shank wrote:
>> >
>> > <snip>
>> >
>> >> I've evolved to the following. I can insert, but it will not update
>> >> if
>> >> a
>> >> similar records exists. I'm assuming I need to do a select to test
>> >> each
>> >> record, then determine if it's an INSERT or UPDATE statement.
>> >> Please
>> >> indulge
>> >> me a bit longer! I get no errors. Only inserts and no updates.
>> >> thanks
>> >>
>> >> <%
>> >> varTextArea =Split(Request.Form("TextArea"), vbCrLf)
>> >>
>> >> Dim DataConn,SQL,cmd,orderno,qty,arParms
>> >>
>> >> DataConn.Open MM_JSK_STRING
>> >> s = "SELECT [AffNo],[OrderNo],[Qty] FROM xTest WHERE WHERE [AffNo]
>> >> = ?
>> >> AND
>> >> [OrderNo] = ?"
>> >> Set rs = DataConn.Execute(s)
>> >>
>> >> If (rs.EOF) Then
>> >> SQL = "INSERT INTO xtest ([AffNo],[OrderNo],[Qty]) "
>> >> SQL = SQL & "VALUES (?,?,?) "
>> >> Else
>> >> SQL="UPDATE xtest SET [Qty] = [Qty] + 1 " & _
>> >> "WHERE [AffNo] = ? AND [OrderNo] = ?"
>> >> cmd.CommandText=SQL
>> >> arParms=array(Session("AffNo"),orderno)
>> >> End If
>> >>
>> >> Set DataConn = Server.CreateObject("ADODB.Connection")
>> >> DataConn.Open MM_JSK_STRING
>> >> Set cmd=createobject("adodb.command")
>> >> with cmd
>> >> .commandtext=SQL
>> >> .commandtype=1 'adcmdtext
>> >> set .activeconnection=DataConn
>> >> end with
>> >>
>> >> response.write "About to start looping.<br>"
>> >> For i = 0 To UBound(varTextArea)
>> >> arrName = Split(varTextArea(i),",")
>> >> orderno=arrName(0)
>> >> qty=arrName(1)
>> >> 'validate the data here, then
>> >> arParms=array(Session("AffNo"),orderno,qty)
>> >> response.write "About to insert " & orderno & " and " & _
>> >> qty & " into the database table.<br>"
>> >> cmd.Execute ,arParms,128 'adExecuteNoRecords
>> >> Next
>> >> %>
>> >
>> > According to the above code, and your previous posts, what you are
>> > trying to do is to take a series of order numbers with associated
>> > quantities, then checking to see if identical value pairings already
>> > exist in the database. If they do not, you insert a new record. If
>> > they do, you increment the quantity associated with the order number
>> > by
>> > 1.
>> >
>
> Possible correction - I would guess that you are not looking for
> identical entries on both order number AND quantity, you are just
> looking to see if the order number already exists in the database
> before performing an Update on the quantity for that order number,
> rather than Inserting a complete new row. Is that correct?
>
> --
> Mike Brind

--------------------------------
The match would be AffNo and OrderNo.
That criteria would define whether the record is inserted or updated.
It associates the product to the user ordering it.
There will be many users adding to the database, day after day.
thanks!

This should do it:

Dim DataConn,SQL,cmd,orderno,qty,arParms, varTextArea

Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open MM_JSK_STRING
Set cmd=createobject("adodb.command")
cmd.commandtype=1 'adcmdtext
set cmd.activeconnection=DataConn

varTextArea =Split(Request.Form("TextArea"), vbCrLf)

For i = 0 To UBound(varTextArea)
arrName = Split(varTextArea(i),",")
orderno=arrName(0)
qty=arrName(1)
'validate data
s = "SELECT [OrderNo],[Qty] FROM xTest WHERE " & _
"[AffNo] = ? AND [OrderNo] = ?"
arrParms=array(Session("AffNo"),orderno)
cmd.commandtext=s
Set rs = cmd.Execute(,arrParms)

If (rs.EOF) Then
SQL = "INSERT INTO xtest ([AffNo],[OrderNo],[Qty]) " & _
"VALUES ('" & Session("AffNo") & "',?,?) "
arParms=array(orderno,qty)
Else
SQL="UPDATE xtest SET [Qty] = [Qty] + " & qty & _
" WHERE [AffNo] = ? AND [OrderNo] = ?"
arParms=array(Session("AffNo"),orderno)
End If

cmd.commandtext=SQL
cmd.Execute ,arParms,128 'adExecuteNoRecords
rs.close : set rs = nothing
Next
'clean up

There's no data validation within this code, and others might find a
couple of ways to improve its efficiency etc.

--
Mike Brind

---------------------------------------
This is great! Thanks!
Mar 16 '06 #24

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Job Lot | last post by:
I have tab delimited text file which gets populated on daily basis via automated process. New entry is written at the bottom. I need to create a utility which makes a copy of this file with 10 most...
1
by: John B. Lorenz | last post by:
I'm attempting to write an input routine that reads from a comma delimited file. I need to read in one record at a time, assign each field to a field array and then continue with my normal...
5
by: Christine | last post by:
I have code right now that reads in the file into an arraylist, but it reads in each line of the text file as a single element rather than the separate tab delimited strings in the line. Is there...
3
by: Leonard Wright | last post by:
I'm developing a lottery program and want read a text file that has Draw date Draw number six lottery numbers all in comma delimited text file I want the user to select a draw number to show...
1
by: svijay | last post by:
hi I have got a strange problem. May I know any solution for this. Here is the detailed description about the problem We have got a mainframe system and also production and development...
8
by: stephane8 | last post by:
I'm able to open and read my .csv file. But when the character "-" is in one of my fields (ex : 18802-002) I get a system.DBNull value ! Even if I edit the file with notepad and put "18802-002" I...
6
by: =?Utf-8?B?UmljaA==?= | last post by:
'--this code works but only reads text into one column when contains multiple cols Dim ds1x As New DataSet Dim ConStr As String = _ "Provider=Microsoft.Jet.OLEDB.4.0;Data...
2
by: tshad | last post by:
I have a program that is reading a csv file into a dataset. I want it to read the 1st line as data. But it ignores it. I have the Connection set up as: OleDbConnection csvConnection = new...
1
by: yesvee | last post by:
Hello All, I'm new for Python programming and I'm having some issues parsing a delimited text file. Any help, suggestions and advice is really appreciated. Thanks a lot in advance. ...
1
by: =?Utf-8?B?UmljaA==?= | last post by:
In the Registry at HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Jet \ 4.0 \ Engines \ Text the default key for Text Format is: "Format" = "CSVDelimited" I can use the following OleDB...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.