Get ready for BLACK FRIDAY shopping starting in

Forums

This topic is locked

4th try, is this possible or not ?

Posted 23 Apr 2002 15:59:40
1
has voted
23 Apr 2002 15:59:40 Dennis van Galen posted:
Hello this will be my 4th request for some help with this.

I need to insert multiple records in a static Dbase table.

I have a table PROGRAMS, this holds all our programs.
I have a table CUSTOMERS, this holds all our customers.
I have a table CUSTPORTFOLIO, I want to store the programs that our customers use in there, so I created a page with a checkbox (as described in certain tutorials) and I cannot find ANY reference on how to procede. I repeated the thing but am stuck on what is supposed to happen when I click submit.
I found a tutorial on multiple update which is utterly pointless ( www.chronoworks.com/ud40/tutorial7/ ).

Other tutorials like www.shehabcorp.com/alfdev/tuts/multi.asp are also pointless because I need it to be Jscript not VB.

Any usefull pointers are welcome, although i'm beginning to doubt there is any, since this is the 4th time i'm asking and nobody bothers to respond.

So if you can help, please do.

Thank you.

Dennis

Replies

Replied 23 Apr 2002 18:59:17
23 Apr 2002 18:59:17 Andrew Watson replied:
Think about it this way....

If you have a recordset or an array that contains the multiple records to be added then just do a while loop around an insert command stepping through the records, Inserting each, one after the other.

How do you determine your multiple recordset?

Do you want to select (using checkboxes) from a currently displayed recordset?

Clarify your Problem..

Its all Possible, by the way.

(And im not interested in your Extension )<img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>

:: Son, im Thirty.... ::
Replied 23 Apr 2002 22:41:24
23 Apr 2002 22:41:24 Dennis van Galen replied:
Clarify my problem, I will do better, I will rephrase my situation.

Table Producten - Unique field: ProductID (inserts into field "PortfolioID" of table "CUSTPORTFOLIO"
Table Klanten - Unique field: klantID
Table KlantPortfolio - Unique field: KlantPortfolioID

Combine those 3 and you have all 3 fields in the CUSTPORTFOLIO table.

My page lists the programs with checkbox next to the name and this is repeated, as I stated in my original message.

Here's the current code for my form:

&lt;form name="form1" method="POST" action="&lt;%=MM_editAction%&gt;"&gt;
&lt;table width="100%" border="0" cellpadding="2"&gt;
&lt;tr&gt;
&lt;td class="kopje_bodytekst" align="center"&gt;&lt;b&gt;Selectie&lt;/b&gt;&lt;/td&gt;
&lt;td class="kopje_bodytekst"&gt;&lt;b&gt;Product naam&lt;/b&gt;&lt;/td&gt;
&lt;td class="kopje_bodytekst"&gt;&lt;b&gt;Afdeling&lt;/b&gt;&lt;/td&gt;
&lt;td class="kopje_bodytekst"&gt;&lt;b&gt;Systeembeheerder&lt;/b&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;% while ((Repeat1__numRows-- != 0) && (!rsProducten.EOF)) { %&gt;
&lt;tr&gt;
&lt;td class="bodytekst" align="center"&gt;&lt;b&gt;
&lt;input type="checkbox" name="checkProduct" value="&lt;%=(rsProducten.Fields.Item("ProductID".Value)%&gt;"&gt;
&lt;/b&gt;&lt;/td&gt;
&lt;td class="bodytekst"&gt;&lt;b&gt;&lt;%=(rsProducten.Fields.Item("ProductNaam".Value)%&gt; &lt;/b&gt;&lt;/td&gt;
&lt;td class="bodytekst"&gt;&lt;b&gt;
&lt;%=(rsProducten.Fields.Item("AfdelingNaam".Value)%&gt; &lt;/b&gt;&lt;/td&gt;
&lt;td class="bodytekst"&gt;&lt;b&gt;
&lt;%=(rsProducten.Fields.Item("SysteemBeheerder".Value)%&gt; &lt;/b&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;%
Repeat1__index++;
rsProducten.MoveNext();
}
%&gt;
&lt;/table&gt;
&lt;br&gt;
&lt;table width="100%" border="0" cellpadding="2"&gt;
&lt;tr align="right"&gt;
&lt;td class="bodytekst" width="50%"&gt;
&lt;input type="hidden" name="hiddenKlantID" value="&lt;%=(rsKlant.Fields.Item("klantID".Value)%&gt;"&gt;
&lt;/td&gt;
&lt;td class="bodytekst"&gt;
&lt;input type="submit" name="Submit" value="Toevoegen"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;input type="hidden" name="MM_insert" value="true"&gt;
&lt;/form&gt;


And this is the insert code:

&lt;%
// *** Edit Operations: declare variables

// set the form action variable
var MM_editAction = Request.ServerVariables("URL";
if (Request.QueryString) {
MM_editAction += "?" + Request.QueryString;
}

// boolean to abort record edit
var MM_abortEdit = false;

// query string to execute
var MM_editQuery = "";
%&gt;
&lt;%
// *** Insert Record: set variables

if (String(Request("MM_insert") != "undefined" {

var MM_editConnection = MM_connFISportal2000_STRING;
var MM_editTable = "klantPortfolio";
var MM_editRedirectUrl = "KlantbaseBeheerMenu.asp";
var MM_fieldsStr = "checkProduct|value|hiddenKlantID|value";
var MM_columnsStr = "PortfolioID|none,none,NULL|KlantID|none,none,NULL";

// create the MM_fields and MM_columns arrays
var MM_fields = MM_fieldsStr.split("|";
var MM_columns = MM_columnsStr.split("|";

// set the form values
for (var i=0; i+1 &lt; MM_fields.length; i+=2) {
MM_fields[i+1] = String(Request.Form(MM_fields[i]));
}

// append the query string to the redirect URL
if (MM_editRedirectUrl && Request.QueryString && Request.QueryString.length &gt; 0) {
MM_editRedirectUrl += ((MM_editRedirectUrl.indexOf('?') == -1)?"?":"&" + Request.QueryString;
}
}
%&gt;
&lt;%
// *** Insert Record: construct a sql insert statement and execute it

if (String(Request("MM_insert") != "undefined" {

// create the sql insert statement
var MM_tableValues = "", MM_dbValues = "";
for (var i=0; i+1 &lt; MM_fields.length; i+=2) {
var formVal = MM_fields[i+1];
var MM_typesArray = MM_columns[i+1].split(",";
var delim = (MM_typesArray[0] != "none" ? MM_typesArray[0] : "";
var altVal = (MM_typesArray[1] != "none" ? MM_typesArray[1] : "";
var emptyVal = (MM_typesArray[2] != "none" ? MM_typesArray[2] : "";
if (formVal == "" || formVal == "undefined" {
formVal = emptyVal;
} else {
if (altVal != "" {
formVal = altVal;
} else if (delim == "'" { // escape quotes
formVal = "'" + formVal.replace(/'/g,"''" + "'";
} else {
formVal = delim + formVal + delim;
}
}
MM_tableValues += ((i != 0) ? "," : "" + MM_columns[i];
MM_dbValues += ((i != 0) ? "," : "" + formVal;
}
MM_editQuery = "insert into " + MM_editTable + " (" + MM_tableValues + " values (" + MM_dbValues + "";

if (!MM_abortEdit) {
// execute the insert
var MM_editCmd = Server.CreateObject('ADODB.Command');
MM_editCmd.ActiveConnection = MM_editConnection;
MM_editCmd.CommandText = MM_editQuery;
MM_editCmd.Execute();
MM_editCmd.ActiveConnection.Close();

if (MM_editRedirectUrl) {
Response.Redirect(MM_editRedirectUrl);
}
}

}
%&gt;

As you can see there's tons of places to add a loop, the problem is that my scripting knowledge isn't that advanced, although I wish it was.

You would think extension developers would focus on things like this instead of writing yet another pointless cookie checker or other things located in any decent UDev book, such as my SAMS book.

So how on earth do I loop this thing, or am I still providing insufficient information ?

And for something similar in a different section, can I just replace the table names with variables that hold my table names ? That other section works with radio buttons, two sections of 5 radio buttons with 1 checkbox, for a knowledge-base.

Note to self: Complain to Agora intranet team about the ban on VB-script.

Thank you for your assistance <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

Dennis

One piece of vital info missing...The Customer recordset returning the KlantID is offcourse filtered on a URL param.

Edited by - djvgalen on 23 Apr 2002 23:56:37
Replied 24 Apr 2002 10:11:46
24 Apr 2002 10:11:46 Andrew Watson replied:
Ill get back to you Dennis, As this is JScript, ill need to work out the code...

PS, Why the BAN on VBScript ?? or is it just not what they want?

Cheers
Leed

:: Son, im Thirty.... ::
Replied 24 Apr 2002 18:34:36
24 Apr 2002 18:34:36 Dennis van Galen replied:
My thanks in advance Leed, for now i made a crude workaround.

The ban on VB script only goes for the Intranet servers under Agora control and I think they banned VB because there's like 200 departments, each with own websites and secure apps running on a big nr. of servers, the ban goes hand in hand with the rules ALL .asp pages must be checked before uploading and NO MS-Access Dbases on the Agora servers.

The .asp check and no MS-Access I can understand in a company the size of KPN Telecom, but the VB ban I do not understand, maybe Henk, the Agora .asp guy doesn't know VB. Or, as you say, maybe they just don't want VB on their servers. I'd have to ask them.

Regards,

Dennis

Reply to this topic