39258

Populate dropdownlistbox items from SQL table in PowerBuilder Classic 12.5

Question:

I have been working on Vb.net but i switched to PowerBuilder 12.5 Classic, I am finding my way around. I need to know the equivalent PowerBuilder script;

<ol><li>to clear a control "textbox1.clear()"</li> <li>to focus "textbox1.focus()"</li> <li>to insert SQL database items to drop-down listbox </li> </ol><pre class="lang-default prettyprint-override"> While dr.Read ComboBox1.Items.Add(dr("itemname")) end while

Answer1:

<ol><li>textbox1.Reset()</li> <li>textbox1.SetFocus()</li> <li>example (untested, but it shows the idea):</li> </ol><pre class="lang-default prettyprint-override"> string ls_sql, ls_syntax, ls_errors ls_sql = "select name from users" ls_syntax = sqlca.SyntaxFromSql(ls_sql, "", ls_errors) if len(ls_errors) > 0 then return datastore ds ds = create datastore ds.create(ls_syntax, ls_errors) if len(ls_errors) = 0 then ds.SetTransObject(sqlca) ds.Retrieve() long ll_row,ll_rows string ls_val ll_rows = ds.RowCount() for ll_row = 1 to ll_rows ls_val = ds.GetItemString(ll_row, "name") Combobox1.AddItem(ls_val) next end if destroy ds

<em><strong>Edit</strong></em> some comments: as Terry says in its answer, the Datawindow and the DataStore are the key controls of Powerbuilder. Consider the DataStore as a VB recordset and the DW is a kind of visual recordset (that can show the data in the way of a form, a grid, ...).

I answered you question by using a DS to retrieve the data and to easily iterate on it (it is easier to manipulate than a cursor) and I translated the filling of the combobox. But as Terry said, you should study how to use a DropDownDataWindow that is way more powerful and evolutive.

Answer2:

To answer while completely ignoring your questions...

Keep in mind that the power of PowerBuilder is in the DataWindow. Loading a dropdown from the database is as simple as setting some attributes on a DataWindow column by making the column a DropDownDataWindow edit style. Depending on what you need, after the DDDW attributes are set, the DDDW values will be loaded when the primary DataWindow is retrieved, no code required (beyond that to set up the database connection with the primary DataWindow and to retrieve the primary DataWindow). In fact, the DDDW gives additional power over a combo box, as its dropdown is another DataWindow, so it can have multiple columns, headers, graphics, row-based expressions, conditional colouring, item "rows" that are multiple text lines tall, etc.... You leave yourself open to more opportunities by going with the DataWindow. (I know. I walked out of my Intro to PB course, thought DWs were overblown, and tried to program without them. Learned an appreciation for all they do <strong>very</strong> quickly. Gave up my non-DW approach on the next project.)

Good luck,

Terry

Recommend

  • Datagridview to Clipboard with formatting
  • Increment inside angular expression
  • Run-time Error 424 Object Required UserForm doesnt exist
  • Prevent duplicates from adding items from Listbox1 to Listbox2 (VBA excel)
  • Bind Combobox with huge data in WPF
  • Why Is My Azure SQL Database Table Permanently Locked?
  • Accesing WinCE ComboBox DroppedDown property (.NET CF 2.0)
  • QStandardItemModel::removeRows() does not work in my use case
  • How to integrate a custom GraphicsItem into a QML scene?
  • Does derived class' member functions inherit virtualness from base class?
  • Getting webGL error in autodesk viewer
  • How to correctly append dynamic GetUIKit accordions?
  • Is there a way to clear some session data from ALL sessions?
  • PHPUnit: Expected status code 200 but received 419 with Laravel
  • ExecuteNonQuery not working in C#
  • Content-Length header not returned from Pylons response
  • Play WS (2.2.1): post/put large request
  • How to access EntityManager inside Entity class in EJB3
  • vba code to select only visible cells in specific column except heading
  • Release, debug version and Authorization Google?
  • jquery mobile loadPage not working
  • Apache 2.4 - remove | delete | uninstall
  • How to delete a row from a dynamic generate table using jquery?
  • Python: how to group similar lists together in a list of lists?
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Codeigniter doesn't let me update entry, because some fields must be unique
  • Free memory of cv::Mat loaded using FileStorage API
  • Trying to get generic when generic is not available
  • Getting Messege Twice Using IMvxMessenger
  • Change div Background jquery
  • How to get Windows thread pool to call class member function?
  • Bitwise OR returns boolean when one of operands is nil
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • Busy indicator not showing up in wpf window [duplicate]
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?