Results 1 to 9 of 9

Thread: using 2 database for Listview function

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    93

    using 2 database for Listview function

    if i need to link two database to one listview, i had written the following but it doesn't seems to work. can someone help me out with this??
    The subrecordset doesn't seems to able to extract data from database




    Dim sqlstring As String
    Dim sqlstring2 As String


    sqlstring = "SELECT * FROM APPOINTMENT_T WHERE APPOINTMENT_DATE = #" & Apptdate2 & "# ORDER BY APPOINTMENT_DATE, START_TIME"


    mainRecordset.Open sqlstring, mainConnection, adOpenKeyset, _
    adLockOptimistic, adCmdText


    If mainRecordset.RecordCount <> 0 Then
    mainRecordset.MoveFirst

    IC.Text = mainRecordset.Fields("PATIENT_ID").Value
    sqlstring2 = "SELECT * FROM PATIENT_RECORD_T WHERE NRIC = '" + IC.Text + "' "
    subrecordset.Open sqlstring, mainConnection, adOpenKeyset, _
    adLockOptimistic, adCmdText

    Do While Not mainRecordset.EOF

    If mainRecordset.RecordCount <> 0 And subrecordset.RecordCount <> 0 Then
    subrecordset.MoveFirst
    With ListView

    With ListView.ListItems.Add(, , Format(mainRecordset.Fields("PATIENT_ID").Value, "dd-mmm-yy"))
    .SubItems(1) = subrecordset.Fields("FIRSTNAME").Value
    .SubItems(2) = subrecordset.Fields("MIDDLENAME").Value
    .SubItems(3) = subrecordset.Fields("LASTNAME").Value
    .SubItems(4) = Format(mainRecordset.Fields("START_TIME").Value, "hh:mm AMPM")
    .SubItems(5) = mainRecordset.Fields("PURPOSE").Value
    End With

    mainRecordset.MoveNext
    End With


    End If
    Loop

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: using 2 database for Listview function

    Do you actually mean two databases, or is it two tables in the same database? (it is a very big difference).

    Next question, what data type is the NRIC field?

    And finally.. is there a particular reason for the listview, as opposed to an MSHFlexGrid? (which can show child recordsets nicely).

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    93

    Re: using 2 database for Listview function

    i think i shall rephrase my question
    coz it seems a bit blur. so sorry


    imagine i have 2 table, A and B, if there is a similar field C
    how can i place a SELECT statement which ensure the field C in A and B are equal??

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: using 2 database for Listview function

    Do you want to return data from both tables in the same recordset?

    If not, then basically what you had before (but you need to at least answer my second question above to be sure this is right).

    If you do want it all in the same RS, use SQL like this:
    Code:
    SELECT TableA.Field1, TableB.Field2, ...
    FROM TableA INNER JOIN TableB ON (TableA.FieldC = TableB.FieldC)
    ORDER BY ....

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    93

    Re: using 2 database for Listview function

    i tried the below

    sqlString = "SELECT * FROM USER_LOGIN_T INNER JOIN PATIENT_RECORD_T WHERE (PATIENT_RECORD_T.NRIC = USER_LOGIN_T.NRIC AND FIRSTNAME LIKE '%" + TextFirstname.Text _
    + "%' AND MIDDLENAME LIKE '%" + TextMiddlename.Text _
    + "%' AND LASTNAME LIKE '%" + TextLastname.Text _
    + "%' AND NRIC LIKE '%" + TextNRIC.Text + "%' )"


    but it said error in FROM clause

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: using 2 database for Listview function

    The Join information goes into an "ON" clause, not the Where clause. Try this:
    VB Code:
    1. sqlString = "SELECT * " _
    2.           & "FROM USER_LOGIN_T " _
    3.           & "INNER JOIN PATIENT_RECORD_T ON (PATIENT_RECORD_T.NRIC = USER_LOGIN_T.NRIC) " _
    4.           & "WHERE FIRSTNAME LIKE '%" & TextFirstname.Text _
    5.           & "%' AND MIDDLENAME LIKE '%" & TextMiddlename.Text _
    6.           & "%' AND LASTNAME LIKE '%" & TextLastname.Text _
    7.           & "%' AND NRIC LIKE '%" & TextNRIC.Text & "%' )"
    Oh, and you should always use & for joining strings in VB - it's quicker, and removes the chances of accidental arithmetic.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    93

    Re: using 2 database for Listview function

    thanks for ur help but it states the NRIC could refer to more than 1 table from ur sql statements

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: using 2 database for Listview function

    Quote Originally Posted by xiaofeiii
    thanks for ur help but it states the NRIC could refer to more than 1 table from ur sql statements
    It probably doesn't like this
    Code:
    & "%' AND NRIC LIKE '%" & TextNRIC.Text & "%' )"
    Which table are you referring to here, RECORD_T or LOGIN_T?

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: using 2 database for Listview function

    As that field is the one being joined on, it doesn't actually matter. This would fix it:
    VB Code:
    1. & "%' AND PATIENT_RECORD_T.NRIC LIKE '%" & TextNRIC.Text & "%' )"

Posting Permissions

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



Click Here to Expand Forum to Full Width