473,786 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Vbscript "SPLIT" function on Multi-select field

I am using the following code to split/join values in a multi-select
field. It is combining all the values in All the records into one long
string in each record in recordset.

Example: I have a recordset with 2 records.
The 1st contains the split/joined values: Alan Smir, Jeff Karl
The 2nd contains the value: Keith Robb

When it updates database, it will put Alan Smir, Jeff Karl, Keith Robb
into each record in the recordset
Instead it should be putting Alan Smir, Jeff Karl into the 1st record
and Keith Robb into the 2nd record in the recordset.
Does anyone see what is wrong with the code?

<% strID = split(request.f orm("Proj"), ", ")
mdgarray1 = split(request.f orm("mgrgroup") , ",")
redim mdgarray2(uboun d(mdgarray1))
for i = 0 to ubound(mdgarray 1)
mdgarray2(i) = Split(mdgarray1 (i)," - ")(0)
next
mgrgrp = Join(mdgarray2, ", ")

FOR i = LBound(strID) TO UBound(strID)
mySQL = "UPDATE ERoj SET mgrgroup= '" & trim(mgrgrp) & "' where (id ='"
& strID(i) & "')"
dbRoj.Execute(m ySQL)
NEXT
%>

Feb 14 '06 #1
11 12622
pmarisole wrote:
I am using the following code to split/join values in a multi-select
field. It is combining all the values in All the records into one long
string in each record in recordset.

Example: I have a recordset with 2 records.
The 1st contains the split/joined values: Alan Smir, Jeff Karl
The 2nd contains the value: Keith Robb

When it updates database, it will put Alan Smir, Jeff Karl, Keith Robb
into each record in the recordset
Instead it should be putting Alan Smir, Jeff Karl into the 1st record
and Keith Robb into the 2nd record in the recordset.
Does anyone see what is wrong with the code?


Not without seeing the result of :
Response.Write request.form("P roj") & "<BR>"
Response.Write request.form("m grgroup") & "<BR>"

Also, show us the two SQL statements you wish this code to generate and
execute.

--
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.
Feb 14 '06 #2
1st Record Value
Alan Smir, Jeff Karl
2nd Record Value
Keith Robb

response.write mgrgrp
response.write "<br>"
response.write strID(i)
response.end

This is the output from response.write for the two records
Alan Smir, Jeff Karl, Keith Robb (it's combining all the values in
both records into ONE VALUE)
60691908 (this is the 1st strID in the loop)

This is the SQL statement that I am using to update the database
FOR i = LBound(strID) TO UBound(strID)
mySQL = "UPDATE ERoj SET mgrgrp= '" & trim(mgrgrp) & "' where (id ='"
& strID(i) & "')"
dbRoj.Execute(m ySQL)
NEXT

Feb 14 '06 #3
pmarisole wrote:
1st Record Value
Alan Smir, Jeff Karl
2nd Record Value
Keith Robb
Yes, you said this in your first message. It is not a valid statement, but I
let it pass (records contain fields - you have not shown me any field names)

response.write mgrgrp
response.write "<br>"
response.write strID(i)
response.end
Why are you showing me this? I did not ask to see it.
Please read my reply again. I asked to see the result of:

Response.Write request.form("P roj") & "<BR>"
Response.Write request.form("m grgroup") & "<BR>"

In fact, run this code:

Response.Write "request.form(" "Proj"") contains:<BR>"
Response.Write request.form("P roj") & "<BR>"
Response.Write "request.form(" "mgrgroup"" ) contains:<BR>"
Response.Write request.form("m grgroup") & "<BR>"

and show me that result.

This is the output from response.write for the two records
Alan Smir, Jeff Karl, Keith Robb (it's combining all the values
in both records into ONE VALUE)
Well, that's one clue as to what is going on, isn't it?
60691908 (this is the 1st strID in the loop)

This is the SQL statement that I am using to update the database


No, it is not. This is the series of vbscript statements that is supposed to
generate the sql statements to be executed.

Bob Barrows

--
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.
Feb 14 '06 #4
THIS IS THE ENTIRE CODE WITH THE OUTPUT YOU REQUESTED
<%Option Explicit%>
<!--#INCLUDE FILE="adovbs.in c"-->
<%
Dim dbProject,mdgar ray1, mdgarray2(), mddarray1, mddarray2()
Dim mySQL, strID, i, j, idate,pdate
Dim projstat,impr,m dg, mgrgrp

'On Error Resume Next
Set dbProject = Server.CreateOb ject("ADODB.Con nection")
%>
<!--#INCLUDE FILE="../../includes/EBS/eproj1.asp"-->
<% strID = split(request.f orm("Proj"), ", ")
projstat = split(request.f orm("projstat") ,",")

mdgarray1 =split(request. form("mgrgroup" ), ",")
redim mdgarray2(uboun d(mdgarray1))
for i = 0 to ubound(mdgarray 1)
mdgarray2(i) = Split(mdgarray1 (i)," - ")(0)
next
mgrgrp = Join(mdgarray2, ", ")

FOR i = LBound(strID) TO UBound(strID)
mySQL = "UPDATE EBSProjects SET mgrgroup= '" & trim(mgrgrp) & "'
where (ebsrefid ='" & strID(i) & "')"
dbProject.Execu te(mySQL)
NEXT
Response.Write "request.form(" "Proj"") contains:<BR>"
Response.Write request.form("P roj") & "<BR>"
Response.Write "request.form(" "mgrgroup"" ) contains:<BR>"
Response.Write request.form("m grgroup") & "<BR>"
response.end
%>

HERE'S THE OUTPUT
request.form("P roj") contains:
60691908, 60692155
request.form("m grgroup") contains:
Alan Smir - TJT1, Jeff Karl - HEG2, Keith Robb - TPP3

Feb 14 '06 #5
pmarisole wrote:
THIS IS THE ENTIRE CODE
Oh come on. I did not ask for that. :-)
WITH THE OUTPUT YOU REQUESTED <snip> Response.Write "request.form(" "Proj"") contains:<BR>"
Response.Write request.form("P roj") & "<BR>"
Response.Write "request.form(" "mgrgroup"" ) contains:<BR>"
Response.Write request.form("m grgroup") & "<BR>"
response.end
%>

HERE'S THE OUTPUT
request.form("P roj") contains:
60691908, 60692155
request.form("m grgroup") contains:
Alan Smir - TJT1, Jeff Karl - HEG2, Keith Robb - TPP3


Now, what to the two sql statements you wish to generate look like? I'm
going somewhere with this. I just want to make sure you see where I'm going.
Pretend you are opening your database in Access and creating queies in SQL
View to accomplish your task. What will those sql statements look like?

--
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.
Feb 14 '06 #6
This is the SQL
FOR i = LBound(strID) TO UBound(strID)
UPDATE EBSProjects SET mgrgroup= '" & trim(mgrgrp) & "' where (ebsrefid
='" & strID(i) & "')"
NEXT

In english terms
FOR i = LBound(strID) TO UBound(strID)
UPDATE EBSProjects SET mgrgroup = 'Alan Smir, Jeff Karl ' where
ebsrefid = 60691908
Next
UPDATE EBSProjects SET mgrgroup = Keith Robb ' where ebsrefid =
60692155

Feb 14 '06 #7
I am new at this and I don't know what other code to use except this.

Feb 14 '06 #8
pmarisole wrote:
This is the SQL
Again, it is not the SQL. It is a series of vbscript statements intended to
generate the SQL
FOR i = LBound(strID) TO UBound(strID)
UPDATE EBSProjects SET mgrgroup= '" & trim(mgrgrp) & "' where
(ebsrefid ='" & strID(i) & "')"
NEXT

In english terms
OK, here are the two SQL statements you wish your vbscript to generate::
UPDATE EBSProjects SET mgrgroup = 'Alan Smir, Jeff Karl ' where
ebsrefid = 60691908 UPDATE EBSProjects SET mgrgroup = Keith Robb ' where ebsrefid =
60692155


Now, let's look at the results of the Response.Writes I asked for:

request.form("P roj") contains:
60691908, 60692155
request.form("m grgroup") contains:
Alan Smir - TJT1, Jeff Karl - HEG2, Keith Robb - TPP3

Now ... imagine that you don't know which piece of data belongs in which sql
statement. How would you plan to separate out the data to put each piece in
the correct sql statement?
....
I'm waiting. Think about it ....

All you have available is the information presented above. How do you take
"Alan Smir - TJT1, Jeff Karl - HEG2, Keith Robb - TPP3" and break it up into
'Alan Smir, Jeff Karl ' and 'Keith Robb ' without knowing ahead of time
which names were supposed to go with which record?
....

You can't come up with a way, can you?
Well, neither can I. Do you see what the problem is?

.....

The problem is: you have not provided enough information to enable the code
to make the proper decisions. There is nothing there to tell it that 'Alan
Smir, Jeff Karl ' are supposed to go into the record for 60691908, and that
'Keith Robb ' is supposed to go into the record for 60692155.

What you need to do is go back to your data-entry form and incorporate the
ebsrefid into the names of the mgrgroup input elements. So, instead of
request.form("m grgroup")
you will have
request.form("m grgroup_6069190 8") and request.form("m grgroup_6069215 5")

Once you have accomplished this, you can change your processing code to (the
following is tested and works - you can test it yourself.):

<%
dim arID, strID, arMgrs(), strMgr, mgrgrp, mySQL, i
if len(request.for m("Proj"))> 0 then
'arID = Split(request.f orm("Proj"),"," )
'for each strID in arID
for each strID in request.form("P roj")
mgrgrp=""
if len(request.for m("mgrgroup_" & strID)) > 0 then
'arMgrs=Split(r equest.form("mg rgroup_" & strID),",")
Redim arMgrs(request. form("mgrgroup_ " & strID).Count -1)
i = 0
for each strMgr in request.form("m grgroup_" & strID)
arMgrs(i)=RTrim (split(strMgr,"-")(0))
i = i + 1
next
mgrgrp=Join(arM grs,",")
end if
mySQL = "UPDATE ERoj SET mgrgroup= '" & trim(mgrgrp) & _
"' where (id ='" & strID & "')"
Response.Write mySQL & "<BR>"
next
end if
%>
<HTML>
<BODY>

<form method="post">
<table>
<tr><td><inpu t type="text" name="Proj" value="60691908 "></td>
<td>
<input type="text" name="mgrgroup_ 60691908"
value="Alan Smir - TJT1"><BR>
<input type="text" name="mgrgroup_ 60691908"
value="Jeff Karl - HEG2">
</td>
</tr>
<tr><td><inpu t type="text" name="Proj" value="60692155 "></td>
<td>
<input type="text" name="mgrgroup_ 60692155"
value="Keith Robb - TPP3">
</td>
</tr>
</table>
<INPUT type="submit" value="Submit">
</form>

</BODY>
</HTML>

Of course, my preference would be to use parameters instead of dynamic sql,
but I think I've given you enough to think about here.

Bob Barrows

--
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.
Feb 14 '06 #9
I did as you suggested and it works just great.
I really appreciate you help with this.

Feb 14 '06 #10

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

Similar topics

11
2508
by: Carlos Ribeiro | last post by:
Hi all, While writing a small program to help other poster at c.l.py, I found a small inconsistency between the handling of keyword parameters of string.split() and the split() method of strings. I wonder if someone else had ever stumbled on it before, and if it has a good reason to work like it is. Both implementations take two parameters: the separator character and the max number of splits (maxsplit). However, string.split() accept
3
10529
by: Reb | last post by:
Hi, I could split only by a character. How do i split by a string. How can i do something like this. e.g., somestring.Split("name"); Thanks Reb
1
3745
by: Mike P | last post by:
I am using Split to split get a number of items from a multi line text box. But I need to be able to get the number of elements within the text box (e.g. if the text box has 2,4,8 in it, I want to be able to count that this text box has 3 elements entered into it). My code is below : for (int p=0; p < dgNational.Items.Count; p++) { strQuantity = ((TextBox)dgNational.Items.FindControl("txtAccount")).Text +"\r\n";
7
4472
by: Christine | last post by:
My code has a split function that should split the text file of numbers. I've run this in previous programs as it is here and it worked, but now it wont work for some reason and returns System_String. I don't see a difference in the previous code and what I have now. Can anyone find where I went wrong? Thanks a bunch! //Open new stream reader and writer to read in file //And write to a new file. StreamWriter swa=new...
4
17351
by: mannyGonzales | last post by:
Hey guys, Very common task: read a csv file. My data reads as: "1","2","3", my code reads this way: While filename.Peek > -1 instr = filename.ReadLine indata = Split(instr, ",")
3
13022
by: amitsoni.1984 | last post by:
Hi, I have to write a code in python to read a matrix from a text file and for that i am using following code. But it gives an error saying "NameError: name 'split' is not defined". Can anyone help me with this. ------------------------------------------------- #!/usr/bin/python import numpy file = open('matrix.txt', 'r')
4
1454
by: grey15 | last post by:
hi to all......am very new to perl....so dnt knw much abt it.... i have a txt file.....so i have to split the values using delimiters.eg have following text- Colombian|The finest Colombian beans, low flame roasted to yield a rich flavour.|7.99| but when i use the split function using '|' as delimiter, it gives me errors- use of uninitialized value in concatenation (.) or string i used the following function split(/|/,$_);
1
2436
by: John | last post by:
Hi I have written a Split function which in turn calls the standard string split function. Code is below; Function Split1(ByVal Expression As String, Optional ByVal Delimiter As String = " ", Optional ByVal Limit As Integer = -1, Optional ByVal Compare As CompareMethod = CompareMethod.Binary, Optional ByVal MaxLength As Integer = 0) As String()
5
2231
by: nagmvs | last post by:
Can anyone tell me about the usage of split function in Asp with Example ? i done one project using split function.and i have some problems regarding storing data in data base.I use there variables.the data in the two variables is stored correctly.But the third variable data is stored some where. So please tell me some different tech. oh using split function in ASP using VB.NET. thanks,
19
66223
by: fellya | last post by:
Hi, i don't have enough experience in writing codes in Python but now i'm trying to see how i can start using Python. I've tried to write a simple program that can display a sentence. now my problem is how to write a code using split function to split that sentence into words then print out each word separately. let me give u an example: >>>sentence=" My question is to know how to write a code in Python" then the output of this...
0
9492
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10360
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10163
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9960
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7510
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5397
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.