Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Data insert from relation tables


Message #1 by ken-mak@r... on Tue, 30 Jan 2001 01:45:45 -0000
hello,



I'd like some help on data insert when I have this kind of relation to 

my database...



Here is my 3 tables:

Student (studentid, sname, sex)

Course (courseid, cname)

Course_taking (studentid, courseid)



for example the course_taking table will look like this, they are both key

to the table.



studentid courseid

--------- --------

1         1

1         2

1         3

2         1

2         3

2         4



On one form I'd like to have 2 list menu,

one for sname (single select), 

and the other for cname(allow multiple select).



These data should then goes into the course_taking table. 



Do I first create a recordset linking these tables first or is there a

easy way to do this?



Thanks in advance.

Message #2 by "Dallas Martin" <dmartin@z...> on Mon, 29 Jan 2001 21:47:09 -0500
This is a multi-part message in MIME format.



------=_NextPart_000_0008_01C08A3D.080C8410

Content-Type: text/plain;

	charset="iso-8859-1"

Content-Transfer-Encoding: quoted-printable



On first ASP page, you will use two <select></select> inputs.



(I assume you know how to dynamically populate <select></select> inputs 

from

recordsets?)



<select name=3D"studentid" size=3D1>

<option value=3D"1">Jones, Susan</option>

<option value=3D"2">Smith, Ken</option

.......

</select>



<select name=3D"courseids" size=3D1 MULTIPLE>

<option value=3D"1">Basket Weaving 101</option>

<option value=3D"2">HTML 101</option>

<option value=3D"3">ASP 101</option>

.....

</select>



Your processing ASP page will receive the above fields:

(Be sure to POST your page)



studentid =3D request.form("studentid") ' one value

courseids =3D request.form("courseids") ' multiple values, comma 

separated



' now the split out the courseids

ArrayCourseIDS =3D split(courseids,",")



'Create your UPDATEABLE recordset object

set rsNewCourses =3D Server.CreateObject("ADODB.Recordset")

rsNewCourses.Open "Course_taking", 

connectionString,adOpenKeySet,adLockOptimistic



y =3D ubound(ArrayCourseIDS)-1

for x =3D 0 to y

     rsNewCourses.AddNew

       rsNewCourses.Fields("studentid") =3D studentid

       rsNewCourses.Fields("courseid") =3D ArrayCourseIDS(x)

    rsNewCourses.Update

next



'close everything and set to nothing



Cheers,

Dallas Martin













































----- Original Message -----

From: <ken-mak@r...>

To: "ASP Databases" <asp_databases@p...>

Sent: Tuesday, January 30, 2001 5:07 AM

Subject: [asp_databases] Data insert from relation tables





> hello,

>

> I'd like some help on data insert when I have this kind of relation to 



> my database...

>

> Here is my 3 tables:

> Student (studentid, sname, sex)

> Course (courseid, cname)

> Course_taking (studentid, courseid)

>

> for example the course_taking table will look like this, they are both 

key

> to the table.

>

> studentid courseid

> --------- --------

> 1         1

> 1         2

> 1         3

> 2         1

> 2         3

> 2         4

>

> On one form I'd like to have 2 list menu,

> one for sname (single select),

> and the other for cname(allow multiple select).

>

> These data should then goes into the course_taking table.

>

> Do I first create a recordset linking these tables first or is there a

> easy way to do this?

>

> Thanks in advance.

>

> ---

> FREE SOFTWARE DEVELOPMENT CODE, CONTENT, AND

> INSIGHTS IN YOUR INBOX!

> Get the latest and best C++, Visual C++, Java, Visual Basic, and XML 

tips, tools, and

> developments from the experts.  Sign up for one or more of EarthWeb?s

> FREE IT newsletters at http://www.earthweb.com today! 




$subst('Email.Unsub')

>







  Return to Index