How to read data from a Access database and assign

Results 1 to 6 of 6

Thread: How to read data from a Access database and assign

  1. #1
    B. Agil Guest

    Default How to read data from a Access database and assign

    Hi there!<BR><BR>I have a function written to obtain data from a Access Database and assign variable to it so that it (the value) can be used in another function. How could I achieve that? Here&#039s the function code:<BR><BR>function checkItem(id)<BR>{<BR> var Conn = Server.CreateObject ("ADODB.Connection");<BR> Conn.Open ("MyAccessDB", "LoginID", "Passwd");<BR> var sql = "SELECT passportno FROM Clients";<BR> sql += " WHERE name = &#039" + id + "&#039";<BR> var rs = Conn.Execute (sql);<BR> <BR> if (rs.EOF) return true;<BR> <BR> checkPassport(rs); // ??? how to get the data ???<BR> <BR> rs.Close();<BR> Conn.Close();<BR> return false;<BR>}<BR><BR>I hope somebody can shed a light on this matter. Thanks very much in advance.<BR><BR>B. Agil<BR>KL City

  2. #2
    Brad Kingsley Guest

    Default RE: How to read data from a Access database and as

    In VB you would use something like:<BR><BR>ThisValue = checkPassport(rs)<BR><BR>Hope this helps.<BR><BR>~Brad

  3. #3
    David Torres Guest

    Default RE: How to read data from a Access database and as

    Assuming checkPassport is the function you&#039re wanting to pass the data too...<BR><BR>if not rs.EOF then checkPassport(rs("passportno"))<BR><BR>or<BR><BR>i f rs.EOF then<BR> &#039do nothing<BR>else<BR> checkPassport(rs("passportno"))<BR>end if<BR><BR>Good Luck,<BR>dat<BR><BR> <BR><BR><BR>

  4. #4
    Hugo Mejia Guest

    Default RE: How to read data from a Access database and as

    If the program pointer hits the line "checkPassport(rs); // ??? how to get the data ???", that means that data were retrieved into rs (the recordset). Because you only requested one field (pasportno) from the table, you only get one value per record. That value is at rs(0) (0 represents the first field you requested, 1 would be the next field [if you had asked for another], 2 the next, and so on); using rs("passportno") would be better, though. Therefore, if at this point you made the assignment PassportID=rs(0) (or PassportID=rs("passportno")), the contents of PassportID would be the same as that of the first (and only) field in the first record returned. Now, if your call (rs=Conn.Execute(sql)) had returned several records, then you would need to point to the next record in order to get the second record returned, to the next one for the third and so on. That is done by saying "rs.MoveNext", until eventually you run out of records at which point the value in rs.EOF will be true (you&#039ll then have reached the EndOfFile!).<BR>I hope this was not boring (personnaly, I think it&#039s fun!)<BR>


  5. #5
    B. Agil Guest

    Default RE: How to read data from a Access database and as

    Hi there Mr Mejia,<BR><BR>Thanks for clarifying things out. And yeah, I do think it&#039s fun.. I&#039m having a good time here.. Thanks again.. :)<BR><BR>B Agil

  6. #6
    B. Agil Guest

    Default RE: How to read data from a Access database and as

    Mr Torres,<BR><BR>Thanks. You&#039re da man! <BR><BR>Much respect,<BR>B. Agil

Posting Permissions

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