Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

Custom action to update ComboBox table


4 replies to this topic

anthonyh

anthonyh
  • Full Members
  • 93 posts

Posted 10 May 2002 - 15:06

I need to be able to populate a combo box at runtime. I've written a custom action that gathers the information to be added to the combo box, I then call MsiDatabaseOpenView() to insert the record(s) into the table.  The call fails and it returns invalid handle.

  Is it possible to do this from a custom action?  Or can you only modify tables when the MSI is not in use?



Anthony
Product Availability Developer
Avantis
Invensys Process Systems

Using InstallShield Developer 7.04 - Basic Project

Ian Blake

Ian Blake
  • Members
  • 483 posts

Posted 10 May 2002 - 15:29

You can make temporary changes to most tables with custom actions during installation.

So your code is something like this?

hDatabase=MsiGetActiveDatabase(hMsi);
Result = MsiDatabaseOpenView(hDatabase, YourSQL, &hView);
if (Result==ERROR_SUCCESS)
{
   Result = MsiViewExecute(hView, 0);
   MsiViewClose(hView)
}


'YourSQL' must include the TEMPORARY clause.


Ian Blake
(Currently Unemployed)

anthonyh

anthonyh
  • Full Members
  • 93 posts

Posted 10 May 2002 - 16:26

Thanks.  Now I'm get bad sql syntax.  Here is my sql statement:

"INSERT INTO ComboBox (ComboBox.Property,ComboBox.Order,ComboBox.Value) VALUES ('ENVIRONMENTS',1,'Testing';) TEMPORARY"

Can you let me know what is wrong with it.




Anthony
Product Availability Developer
Avantis
Invensys Process Systems

Using InstallShield Developer 7.04 - Basic Project

hteichert

hteichert
  • Members
  • 158 posts

Posted 13 May 2002 - 09:37

Nothing to your SQL-syntax, but there was another thread in this forum about updating Listboxes during runtime. It's the same for Comboboxes, you only have to change "ListBox" to "ComboBox" in the oDatabase.Openview call. The link:
Populate Custom Dialog Combo Box Items via VBS
h.teichert-ott

anthonyh

anthonyh
  • Full Members
  • 93 posts

Posted 13 May 2002 - 14:59

Still no luck.  I'm doing something wrong here, but can't seem to figure out what it is.  Here is the code that I am using.

//*****************************************************************
  char szSQLQuery[256] = "";
  sprintf( szSQLQuery, "SELECT * FROM ComboBox" );

  PMSIHANDLE hActiveInstall = MsiGetActiveDatabase( hInstall );
  PMSIHANDLE hView;
  UINT uiReturn = MsiDatabaseOpenView( hActiveInstall, szSQLQuery, &hView );
  if ( uiReturn != ERROR_SUCCESS )
  {
     // display error
     return ERROR_INSTALL_FAILURE;
  }

  sprintf( szSQLQuery, "INSERT INTO ComboBox (ComboBox.Property,ComboBox.Order,ComboBox.Value) VALUES ('ENVIRONMENT',%d,'Testing';)", iIndex++ );

  PMSIHANDLE hRecord = MsiCreateRecord( 0 );
  MsiRecordSetString( hRecord, 0, szSQLQuery );

  uiReturn = MsiViewModify( hView, MSIMODIFY_INSERT_TEMPORARY, hRecord );
  if ( uiReturn != ERROR_SUCCESS )
  {
     // display error
     return ERROR_INSTALL_FAILURE;
  }
//*****************************************************************

MsiViewModify() returns ERROR_FUNCTION_FAILED.



Anthony
Product Availability Developer
Avantis
Invensys Process Systems

Using InstallShield Developer 7.04 - Basic Project