Insering multiple values into database

Results 1 to 8 of 8

Thread: Insering multiple values into database

  1. #1
    Laurie Guest

    Default Insering multiple values into database

    Hi,<BR>I have a list box where it has 7 values. I want to have a option of selecting all values or 1 or 4 or 5 values from the list box and inserted into a database. I am using Access 2000. How can I have 7 values in one field??<BR>Can somebody help me on this please?<BR><BR>Thanks.

  2. #2
    James W. Guest

    Default RE: Insering multiple values into database

    You can insert them into one field but I don&#039;t think you&#039;ll want to. When multiple options are selected they are passed with the values separated by commas like so:<BR>val1,val2,val3,val4 etc. <BR>You could insert them into a text field but it will be difficult to work with the values later. Better to separate them and insert into either multiple rows or multiple fields, depending on you needs and database structure. You can separate them with the split() function; click on the VBScript reference link @ the left for more info on Split

  3. #3
    Laurie Guest

    Default RE: Insering multiple values into database

    I thought of entering into different rows but then I will have redundant data. Can I have multiple fields in Access 2000? if yes then how can I establish 1 - many relationship?<BR><BR>Thanks a lot.

  4. #4
    James W. Guest

    Default RE: Insering multiple values into database

    Here&#039;s what I&#039;d do but there are lots of ways. Let&#039;s say I need to store someone&#039;s lastname,firstname and as many of their favorite movies as they want (multiple select).<BR>table 1 is called tblUser<BR>userID AutoNumber<BR>LastName text<BR>FirstName text<BR><BR>table 2 is called tblMoviePicks<BR>userID<BR>MoviePick<BR><BR>Using a unique ID as an identifier of each record allows other tables to establish one to many. In tblMoviePicks, you can have as many records as you want and the userID will link them all to the user in tblUser. You can use AutoNumber or any other absolute unique number (like SSN). <BR>Does this make sense?<BR>

  5. #5
    Join Date
    Dec 1969

    Default Here ya go, try this...

    Okay, you have a textbox that returns more than one value... This code (test it out) will take a form with a list box with multiple values, and return those values...<BR><BR><BR><BR>&#060;%@Language="VBScrip t"%&#062;<BR>&#060;form action="test.asp" method="get"&#062; <BR>&#060;select name="test" size="16" multiple&#062;<BR> &#060;option value="1"&#062;1&#060;/option&#062;<BR> &#060;option value="2"&#062;2&#060;/option&#062;<BR> &#060;option value="3"&#062;3&#060;/option&#062;<BR>&#060;/select&#062;<BR>&#060;input type="submit" name="submit" value="submit"&#062;<BR>&#060;/form&#062;<BR><BR>&#060;% <BR>Dim Arr, sql, gr<BR> &#039;Split the values into an array<BR>Arr = Split(CStr(Request("test")),",") <BR> &#039;Now loop through the array and show what<BR> &#039;The values we retrieved were...<BR>for x = 0 to UBound(Arr) <BR> &#039;This can easily be changed into an insert statement<BR> &#039;Or you can build your SQL statement in this loop<BR> response.write(trim(arr(x)))<BR>next<BR>%&#062;<BR ><BR>This resource was manipulated from this location...<BR><BR><BR>-- Whol

  6. #6
    Laurie Guest

    Default RE: Insering multiple values into database


  7. #7
    Laurie Guest

    Default RE: Here ya go, try this...


  8. #8
    Dalibor Sver Guest

    Default RE: Insering multiple values into database

    Yes you can if we are not talking about primary key field.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts