Below is the code, placed in the CLICK event of the Populate Combo Box button, that populates the combo box. The code is almost identical to the code for populating the combo box from Access. In fact, it is impossible to determine, just by looking at the code, where the data is coming from.

If you would like to populate the combo box automatically, place this code in the CREATE event of the window.  The button would be unnecessary.

In the code, the differences between the two programs is highlighted. They are:

  • Changing the connection name. Use PUBS instead of NWIND. Additionally, Access does not require a user name. SQL Server does require a user name, which we specify as sa, the System Administrator. Your user name may be different. It almost certainly is if you're not the System Administrator. You also may need a password, which is the fourth parameter to QryInstance(). Consult your database administrator.

  • Changing the SQL Select statement. Since the table and columns are different, it makes sense that the SQL Select statement to be executed will change.

  • Changing the Combo Box Name. Control names should be easily referenced. In this example, since the combo box is populated with author names, we named it AUTHORS.

$insert XO_Equates
hXO = XOInstance('PUBS' , '', 'sa')
if hXO then
  hQry = QryInstance(hXO)
    if hQry then
      flag = QryMethod(hQry, QRY_EXECUTE$, "select au_lname + ', ' + au_fname from authors order by au_lname")
      row = ""
      results = ""
      loop
        flag = QryMethod(hQry, QRY_GETROW$, row)
      while flag
        results<-1> = row
      repeat
      QryMethod(hQry, QRY_DESTROY$)
    end
  rv = Set_Property (@window : '.AUTHORS', 'LIST', results)
  XOMethod(hXO, XO_DESTROY$)
end

 

 

  • No labels