Assign ID for database fileds

Results 1 to 2 of 2

Thread: Assign ID for database fileds

  1. #1
    ifred Guest

    Default Assign ID for database fileds

    I have a database with different fields (let’s say 5 fields), each field has a unique ID(1,2,…). I need to write an asp code that will help me to identify the filed by its ID, so when I click a link or something will bring the item from the database. For example, I’ll have 5 links, one for each field, and I need to assign each field to one of the links that will bring it from the database by clicking that link.(can you give me an example please)<BR><BR>Thank you very much<BR>

  2. #2
    Join Date
    Dec 1969

    Default Response 1: The WHERE statement.

    Let&#039s say you have 2 pages [page1.html] which contains the four links and [page2.asp] which gets the records from the database.<BR><BR>******************** page1.html ****************<BR><BR>&#060;a href="page2.asp?id=1"&#062; Get record 1 from database &#060;/a&#062;<BR>&#060;a href="page2.asp?id=2"&#062; Get record 2 from database &#060;/a&#062;<BR>&#060;a href="page2.asp?id=3"&#062; Get record 3 from database &#060;/a&#062;<BR>&#060;a href="page2.asp?id=4"&#062; Get record 4 from database &#060;/a&#062;<BR><BR>******************** page2.asp *****************<BR><BR>&#039We can now get the id from the QueryString<BR>theRecordIDThatYouNeed = Request.QueryString("id")<BR><BR>&#039Set a connection<BR>Set cnn = Server.CreateObject ("ADODB.Connection")<BR>cnn.Open ("DSN=yourDSN")<BR><BR>&#039Now we dynamically create an SQL statement based on <BR>&#039the value of our variable with the very long name.<BR><BR>sql = SELECT idUser FROM tablename WHERE idUser =" & theRecordIDThatYouNeed<BR><BR>Set rst = cnn.Execute (sql)<BR><BR>Response.Write rst(0)<BR><BR>Try it.<BR><BR>HTH<BR><BR>Darren<BR>[ ]

Posting Permissions

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