Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Insert data into 2 tables
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Insert data into 2 tables

 Post Reply Post Reply
Author
judo2000 View Drop Down
Groupie
Groupie
Avatar

Joined: 05 November 2002
Location: United States
Status: Offline
Points: 49
Post Options Post Options   Thanks (0) Thanks(0)   Quote judo2000 Quote  Post ReplyReply Direct Link To This Post Topic: Insert data into 2 tables
    Posted: 18 April 2003 at 12:03pm

I have a form that gets employee information and I want to enter that information into 2 seperate tables.  The name, email, password, etc goes into the employees table and the job title and picture go into the supervisors table.  When the info is inserted into the employees table an empID is generated by an autonumber.  I want to insert the empID from the employees table and the job title and sup picture into the supervisors table and can't get it to work.  Below is what I have to enter the info into the employees table.  This part works.

strSQL = "SELECT employees.empFName, employees.empLName, employees.empWkPhone, employees.empHPhone, employees.empEmail, employees.username, employees.password, employees.groupID, employees.venueID FROM employees"
 
   'set cursor type so we can move through the recordset
   rsSchedules.CursorType=2
 
   'lock the recordset
   rsSchedules.LockType=3
 
   'open connection
   rsSchedules.Open strSQL, adoCon
 
   'Tell the recordset we are adding a new record
   rsSchedules.AddNew
 
   'Add records to the recordset
   rsSchedules.Fields("empFName") = request.Form("Fname")
   rsSchedules.Fields("empLName") = request.Form("Lname")
   rsSchedules.Fields("empHPhone") = request.Form("Hphone")
   rsSchedules.Fields("empWkPhone") = request.Form("wKPhone")
   rsSchedules.Fields("empEmail") = request.Form("email")
   rsSchedules.Fields("username") = request.Form("username")
   rsSchedules.Fields("password") = request.Form("pass")
   rsSchedules.Fields("groupID") = 2
   rsSchedules.Update
   rsSchedules.Requery

Now I can't figure out how to find out what the empID is and then insert it and the other into into the supervisors table.  I would appreciate any help.

Thanks,

Judo2000



Edited by judo2000
If you are not willing to work hard to realize your dreams, why bother dreaming?
Back to Top
glypher View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 25 March 2003
Location: United States
Status: Offline
Points: 38
Post Options Post Options   Thanks (0) Thanks(0)   Quote glypher Quote  Post ReplyReply Direct Link To This Post Posted: 18 April 2003 at 2:51pm

AHHHH!!!!!

first of all... you can clean this all up and put it into the SQL statement.

try something like this:

set nocount on
insert into tbl_A
(item1,item2) VALUES (value1,value2)

at this point there's a magical variable called @@Identity floating around. (the IDentity field of the thing you just put in) so...

set nocount off
insert into tbl_B

(item1,item2) VALUES (@@Identity,value2)

see how that works?

You will need to build the SQL statement to incorperate BOTH of those queries in the same statement. otherwise somehting could come around and snag that other identity before the second transaction fires (HIGHLY unlikely, but could happen) (oh and that nocount thing is there to keep the statement from returning "rows effected" into the second statement.)

 

glypher said so.

GainesvilleBands.com
Back to Top
judo2000 View Drop Down
Groupie
Groupie
Avatar

Joined: 05 November 2002
Location: United States
Status: Offline
Points: 49
Post Options Post Options   Thanks (0) Thanks(0)   Quote judo2000 Quote  Post ReplyReply Direct Link To This Post Posted: 18 April 2003 at 4:08pm

Thanks for the advise, but I'm not really sure how to incorporate that into what I already have or to build the SQL statement to incorporate both inserts?  When I  tried it with the set nocount on it gave me an error saying it need = and with the = it still gave an error.  Anny additional help would be greatly appreciated.

Thanks,

If you are not willing to work hard to realize your dreams, why bother dreaming?
Back to Top
farrukh View Drop Down
Groupie
Groupie
Avatar

Joined: 10 May 2002
Location: Pakistan
Status: Offline
Points: 147
Post Options Post Options   Thanks (0) Thanks(0)   Quote farrukh Quote  Post ReplyReply Direct Link To This Post Posted: 18 April 2003 at 4:24pm

i think these two are the unique in your table.
   rsSchedules.Fields("empEmail") = request.Form("email")
   rsSchedules.Fields("username") = request.Form("username")
so after adding data in the first table make a SELECT query like

strSQL = "SELECT Emp_id from emp where employees.username='username posted by user in the form' and employees.password='password posted by the user'";

it will give you the Id of the person who signups then
make an insert query and add there designations to the superior table.

make sure you have a field which have a uniqueness. for example the email address is the unique and the phone number too.
you know what i mean.

i have collected some nice avatars (37) and smileys (227) here you can download
http://www24.brinkster.com/webmastertool/download.html
Back to Top
judo2000 View Drop Down
Groupie
Groupie
Avatar

Joined: 05 November 2002
Location: United States
Status: Offline
Points: 49
Post Options Post Options   Thanks (0) Thanks(0)   Quote judo2000 Quote  Post ReplyReply Direct Link To This Post Posted: 18 April 2003 at 5:15pm

That makes sense but how can I write that sql statement?

strSQL = "SELECT empID FROM employees WHERE username='request.Form("username")'"  ?

Would that work?

Thanks

If you are not willing to work hard to realize your dreams, why bother dreaming?
Back to Top
farrukh View Drop Down
Groupie
Groupie
Avatar

Joined: 10 May 2002
Location: Pakistan
Status: Offline
Points: 147
Post Options Post Options   Thanks (0) Thanks(0)   Quote farrukh Quote  Post ReplyReply Direct Link To This Post Posted: 19 April 2003 at 4:11pm
strSQL= "SELECT empID from employees where username='" & request.form("username") & "';"

i will work
i have collected some nice avatars (37) and smileys (227) here you can download
http://www24.brinkster.com/webmastertool/download.html
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.