Navigate
Home
ArticleWiki
Forum
Journal
Search
Newsletter
Links
Tech News
expertsrt.com
Welcome Guest.
Username:

Password:

Remember me

master/detail
Welcome, Guest. Please login or register.
August 28, 2008, 01:50:45 PM
11291 Posts in 1243 Topics by 838 Members
Latest Member: gjpino
Experts Round Table Network  |  Serverside Technology  |  ASP  |  master/detail « previous next »
Pages: 1 [2] 3
Author Topic: master/detail  (Read 1472 times)
keneso
Site Builder

Offline Offline

Posts: 32


WWW
« Reply #15 on: March 15, 2007, 12:21:38 PM »

I uploaded the new db here
http://www.internetetc.it/ert/keneso/db_clienti.html

The dropdown should list the "Cognome" field

Translation of the fields

Nome = Name
Cognome = Last name
TipoDoc = Doc type
NumeroDoc = Doc number
Indirizzo = Address
Data = Date
In = In
Out = Out
Post = Position aka terminal

I haven't put the ID inserted by accesss

BTW
I think I am confused about these, I understand what the specific code means, but do I have to create those pages, and I am sure they are the ones you already poste, but I can't distinguish them?
Logged
rdivilbiss
Moderator
*
Offline Offline

Posts: 414



WWW
« Reply #16 on: March 15, 2007, 01:13:22 PM »

I'll put in red the parts that are not quite clear to me

function writeCustomersArray(pName) Is that the table name, and do I have to change it to master, or viceversa?

We are going to write the data to a JavaScript array. pName, will be the name of the array.  If you change it to master. any JavaScript function which references the array, will need to do so by calling master[idx][jdx].

Quote
   if NOT (db_rs.bof AND db_rs.eof) then
      out = "var "& pName &" = new Array();" & vbLF What is that referred to, shall I change it to some fileds I named differently?
      idx = 0
      while NOT db_rs.eof
            out = out & " "& pName &"["& idx &"]=['" see above

pName is just the JavaScript array name.  It has nothing to do with your field names.

Quote
      writeCustomersArray = out & vbLF   same as above

writeCustomersArray is the name of the function.  When we assign a value to the function's name, that is what is returned.  If you change it here, you will need to change every "writeCustomersArray" to reference the correct function name.

Quote
   cmdText = "INSERT INTO log (Nome, Cognome, TipoDoc, NumeroDoc, Indirizzo, Data, in, out, Post ) VALUES (@Nome, @Cognome, @TipoDoc, @NumeroDoc, @Indirizzo, @Data, @In, @Out, @Post)"
I have changed those to be exactly like the db fields, is it ok?

Those are parameter place holders...the names are irrelevant.  I always make mine match my field names as well.

Quote
   addParam "@Nome",adVarChar,adParamInput,CLng(10),pNome,"addDetail 2a" Is that the lenght of the field?

Yes it is the length of the field and it must be passed as a Long Integer, hence the CLng() wrapper.

Quote
v v v This is the new piece in order to add the new user to master, did I put it in the right spot? v v v

Yes you did.

Quote
cmdText = "INSERT INTO master (customerid, key, TipoDoc, NumeroDoc, Indirizzo ) VALUES (@customerid, @key, @TipoDoc, @NumeroDoc, @Indirizzo)" Do they have to be like you put them, or do I have to change them with Nome and Cognome?

I usually match the field names, lile you did above, but they could be @1, @2, @3... it doesn't matter to the function.  It does matter that you use the same parameter names in the addParam command to follow.
 
Quote
rXsafe, rXaddress, rXalpha   
What's the difference, and did I edited them correctly?

If you look in the generalPurpose.asp file, you will see various regular expressions for filtering data.

rX is the prefix on the constant declarations, so rXalpha allows only a..z and A..Z
rXint only allows 0..9
rXaddress only allows characters that commonly are used in US postal addresses, which are not harmful in a database insert.
rXsafe allows about anything, that I feel will not cause a problem with XSS injections, but I hate to use it if I can be more precise about what my expected input should be.  Here I used it many times because I was not sure what your true format would be for many fields.

If the field should only contain letters and numbers with no spaces (maybe the Doc number), use rXalphanumeric.

You can also send getFields a regular expression as a parameter.

So getField("postalCode,^[a-zA-Z]{1,2}[0-9][0-9A-Za-z]{0,1} {0,1}[0-9][A-Za-z]{2}$)

would validate a UK postal code.


Quote
   
   ' check for required fields here
   if (Nome="") then
      Message = "The Nome is required."
   end if
   ' check more if you want

Is that to alert me if I fail to fill in the field, and that I can add as many checks as the form fields?

Yes.  I was to lazy to write all the checks for all the fields <smile>.  You can also check for other things, like relationships required between fields, or whatever.  Probably should make all the Messages like this...

Code:
Message = "The Nome is required.<br>"

So they display nicely.]   
Quote
<%=writeCustomersArray("customers")%>
Is the "customer" the db's table name? Shall I change it to "master"?

actualy, here the parameter "customers" is just setting the name of the JavaScript array.  If you change that name, you'll need to chane all array references in your JavaScript.


[/quote]
function createCustomerSelect()  {
    var tmpHTML = '<select id="myOptions" name="myOptions"';
    tmpHTML += ' onchange="fillFormFields(this.selectedIndex);">';
   tmpHTML = tmpHTML + ' <option>Select...</option>\n';
    for (var idx=0; idx<customers.length; idx++) {
        tmpHTML = tmpHTML + ' <option>' + customers[idx][0] + '</option>\n';
    } same as above
    tmpHTML = tmpHTML + '</select>';
    return tmpHTML;
}
[/quote]

Again, array name, nothing to do with your table name. 


Quote
       } Same as the above, is "customers" the table name corresponding to my "master"?
   }

array name, maybe I should have used jsArray or myArray in the example so as to not have confused you.
 

Quote
colspan="3"><input id="Post" name="Post" type="text" size="24">That is as in position, aka terminal, no zip code</td>

I was having trouble translating. You speak Italian, my wife speaks Vietnamese, VGR sprinkles his comments with French and my son cusses me out in Spanish. I'm an old American-Enlish speaker, and I'm doing my best to keep up with all of you, but I'm bound to misunderstand some. LOL.

Note I added id="" attributes to all your fields.  Necessary for the getElementById(...) commands.

Also, I always make my database field names and form field names match exactly in both name and case.  Same for variables in ASP. It makes it much much easier to know what input field is going to what database field.

Also, If you are running this on a box you control, I would switch from MS Access to MS SQL 2005 Express. It is free, light weight, has some free admin tools (or can be linked to via Access).  It has standard SQL and is much more stable than Access.  It also handles parameterized queries, views and stored procedures, which are impossible with access on the web.

It is a much better learning environment so you don't have to learn Access bad habits. (Weird and limited SQL, etc.)
« Last Edit: March 15, 2007, 07:11:49 PM by rdivilbiss » Logged

Rod
keneso
Site Builder

Offline Offline

Posts: 32


WWW
« Reply #17 on: March 16, 2007, 06:13:10 AM »


The main issue is the location of the database as it has to be read - write to the web server. If you put the database inside the web root, the database can be downloaded by anyone who can guess the name and location (which is why we have a database access library, which traps detailed error messages from revealing this to any browser, yet also allows you to get the messages you need for debugging.  Again, that's already written and has been in production for many years and is stable.

Instead of doing

Code:
Set conn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
conn.Open ConnStr
rs.Open "SELECT * FROM log", conn

Any line of which could error out and reveal the details of your database name, path and connection string info, you will do something like:

Code:
if openCommand(myConnStr,"This page name location 1") then
    getRS(db_rs,"SELECT * FROM log", conn,"This page name location 2")
   '... do whatever with db_rs
    closeRS
    closeCommand
end if

I think I am ok with the default page ( http://www.internetetc.it/ert/keneso/db_clienti.html ) , but I haven't undertstood how to connect to the db, I tried to run the rod_default_o1.asp, and I get this error:

Pagine ASP, ASP 0126 (0x80004005)
Impossibile trovare il file di inclusione "/include/generalPurpose.asp".
/09/ert_default_01.asp, line 16


Translation (though you may not needed)
ASP pages
Impossible to find the inclusion file

Thanks.
Logged
rdivilbiss
Moderator
*
Offline Offline

Posts: 414



WWW
« Reply #18 on: March 16, 2007, 12:22:46 PM »

Make sure you have generalPurpose.asp, thisPageClass.asp and paramSQL.asp saved in your website.

My example is looking for those files to be in the include folder under the web root. Download those at the following link.

http://www.rodsdot.com/downloads/someIncludes.zip
Logged

Rod
keneso
Site Builder

Offline Offline

Posts: 32


WWW
« Reply #19 on: March 16, 2007, 12:59:06 PM »

Thanks,
I had already downloaded them, but I had put them in the same test folder as the page, and had called it includes.

I put it in the root folder (I think), and named it "include", since I don't get the same error, but I get this

Microsoft VBScript compilation (0x800A03EA)
Syntax error
/09/ert_default_01.asp, line 80, column 40
out = "var "& pName &" = new Array();" &


Might be that when editing it I did something unvoluntarilly?!

BTW I tried to locate the line in the generalPurpose about the connction, but I failed to notice it.
Logged
rdivilbiss
Moderator
*
Offline Offline

Posts: 414



WWW
« Reply #20 on: March 16, 2007, 02:22:57 PM »

Looks like and extra & at the end of that line.

Connection string goes in global.asa, which must be in the web root.

Logged

Rod
keneso
Site Builder

Offline Offline

Posts: 32


WWW
« Reply #21 on: March 17, 2007, 04:25:16 AM »

Ok, I corrected the line 80 error, deleting the '&', and it brought me to the next error which was a missing " here
             out = out & " "& pName &"["& idx &"]=['"             (line 83)

At this point I correct it , after going to your original code posted on the previous page of this thread, and I notice that at line 80 (previous error) there was a missing       vbLF

your original code
      out = "var "& pName &" = new Array();" & vbLF

What returned an error
      out = "var "& pName &" = new Array();" &

What worked (at least it wasn't seen as an error)
      out = "var "& pName &" = new Array();"
      out = "var "& pName &" = new Array();" & vbLF

I opted to have the full line
      out = "var "& pName &" = new Array();" & vbLF

It then took me to this error

Microsoft VBScript compilation (0x800A0400)
Expected statement
/09/ert_default_01.asp, line 149
end function


I deleted, though looking at your code seems I shouldn't have, the
end function

And it took me to the next error which appears a loop

Microsoft VBScript compilation (0x800A0414)
Cannot use parentheses when calling a Sub
/09/ert_default_01.asp, line 205, column 57
addCustomer(Nome, Cognome, TipoDoc, NumeroDoc, Indirizzo)


I delete the ')' and returns this

Microsoft VBScript compilation (0x800A03EE)
Expected ')'
/09/ert_default_01.asp, line 205, column 56
addCustomer(Nome, Cognome, TipoDoc, NumeroDoc, Indirizzo


I am going to reupload the code I have at this time, will you kindly take another look at it to see what is causing it?
Most prolly is something I've done, but I really can't see it.

Thank you again.
Logged
rdivilbiss
Moderator
*
Offline Offline

Posts: 414



WWW
« Reply #22 on: March 17, 2007, 09:25:14 AM »

The libraries are 4 or 5 years old, and in production on multiple sites and working.

The default.asp page on my site works, so when recoding to match your database could certainly introduce some errors.

Here's the page as a zip to avoid any copy and past issues.

http://www.rodsdot.com/keneso/default.zip
Logged

Rod
keneso
Site Builder

Offline Offline

Posts: 32


WWW
« Reply #23 on: March 17, 2007, 10:02:23 AM »

Thank you.

I downloaded the file, unzipped it
and when running it I get this
-- There was an openCommand error: writeCust 1 1.

Which I believe refers to this
openCommand Application("keneso"), "writeCust 1"

Which makes me think I should change the "keneso" somewhere, but I don't know, and rely on your patience and help.
Logged
keneso
Site Builder

Offline Offline

Posts: 32


WWW
« Reply #24 on: March 17, 2007, 10:23:06 AM »

Nevermind.

I just saw you used the one with the old db fields, I'll use the old db, and try to change the default to match the new db, one of the two setups should be fine.

I'll disturb you if I'll have problems, meanwhile you can take a rest from this ... hopefully a long one. ;)

But before that can you please upload the db as well, so I can compare the files better.

Thanks a lot again
« Last Edit: March 17, 2007, 10:30:51 AM by keneso » Logged
keneso
Site Builder

Offline Offline

Posts: 32


WWW
« Reply #25 on: March 17, 2007, 01:05:56 PM »

I am really sorry to bug you with something it's very elementary to you, but I've gone thru it again, and again, I used the your default out of the box, but I get the
-- There was an openCommand error: writeCust 1 1.
error

I know I am asking you a lot, but will you please download the previous edited default and the db and check them.

http://www.internetetc.it/ert/keneso/db_clienti/rod_default_01.asp
http://www.internetetc.it/ert/keneso/db_clienti/utenti.mdb

Of course after you got your rest.
I can wait few days for you to recover from the stress. ;)
Logged
rdivilbiss
Moderator
*
Offline Offline

Posts: 414



WWW
« Reply #26 on: March 17, 2007, 02:19:54 PM »

openCommand error: writeCust 1 1.

That means the connection sting parameter was empty in the writeCust function at place holder 1.

Since the code is sending Application("keneso") then IIS isn't recognizing the global.asa.

Restart IIS.

Logged

Rod
keneso
Site Builder

Offline Offline

Posts: 32


WWW
« Reply #27 on: March 18, 2007, 12:34:21 PM »

Quote
Restart IIS.

I also rebooted, but still get the error
-- There was an openCommand error: writeCust 1 1.

I am going to upload them on remote, and try it.

Meanwhile I looked for global.asa on my box, and couldn't find it, is that plausible? Where exactly should it be, and If that is the problem, what should I do?
Logged
rdivilbiss
Moderator
*
Offline Offline

Posts: 414



WWW
« Reply #28 on: March 18, 2007, 03:20:50 PM »

On IIS you can have multiple "APPLICATIONS" e.g. virtual web roots.

Assuming a normal IIS install on a desktop, there should be only one...(too start with), which is default.

Normally the root of the default application in at http://localhost, and at C:\Inetpub\wwwroot\.

global.asa (all lower case) should be in that folder.

Here is a test:

Code
Language: asp (GeSHi-highlighted)
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
Application("Test")="GLOBAL ASA Works"
End Sub
</SCRIPT>

Here is a page to verify the global.asa above works

Code
Language: asp (GeSHi-highlighted)
<%
Response.Write(Application("Test"))
%>

Here are some images of what I see on a default IIS instalation on an XP Pro machine.

Start -> Control Panel -> Administrative Tools -> IIS Manager

navigate the tree on the left to the default web site. 



Right click on the default web site and choose properties, then the home directory tab.



If there is no default application create it by clicking the create button. Click the configuration button, and the mappings tab



You should see the mapping for asa at the top.  Double click on that and you should see....



If all that is okay, there should be no problems.  Close all those dialogs.

On the right side of the IIS manager, the global.asa file should be visible in the right pane.



If something is different you've been messing with the permissions or other web site settings.

If global.asa is not in the correct folder...move it.


« Last Edit: March 18, 2007, 03:30:37 PM by rdivilbiss » Logged

Rod
rdivilbiss
Moderator
*
Offline Offline

Posts: 414



WWW
« Reply #29 on: March 18, 2007, 05:07:39 PM »

And... separating everything nicely, gives us a new default.asp. (I'm getting an error on the addDetailRecord, but I'll figure it out later, (I'm sleepy, sorry)

Okay, I finally had some time to debug my example.  Everything works including adding records to the mater and log tables.  The errors on adding records were related to your/mine use of keywords in the database fields...not a good idea.

The final code, working is still at http://www.rodsdot.com/keneso/default.asp

The download link was also updated to point to an updated copy of the code, and the entire code appears at the bottom of the page.

I realize my db uses slightly different field names than your original, that was for my convenience as a non-Italian speaker.

Note also I removed the auto number from the customers (master) table and use the customerId as the primary key. That is why I have a routine to see if the customer exists before adding any records to either the customer or log tables.

Also, I would not store anything in the log table about the customer except the customerId. That was if other details of the customer change, such as their address or position, you will not need to cascade updated to the log table.

So when you view the log, you simply perform a join on the customer and log tables to display the customer information if you wish to see it.

Regards,
Rod

Logged

Rod
Pages: 1 [2] 3
« previous next »
    Jump to: