Link to home
Start Free TrialLog in
Avatar of DrVannacult
DrVannacult

asked on

Plz help a newbie!

I'm using PB8 Eval
My objective is very simple, just to show all record in grid view! This I've done... I've created a DataWindow with Grid style and attached it into Window object. (In DataWindow I can preview it!) But in the runtime It doesn't seem to show somethings, just a blank! So I can't figure out how to coding it to show all record like preview's time! I'm a very newbie on PB

Thanks very much all experts,
newbie to PB
drvannacult
Avatar of pbguy
pbguy

Hi Doc!

Let's see if I can get you through... I'll list the steps you need to get data displayed on a datawindow on your screen.  Let me know what you did/didn't do :

1.Create a datawindow object using the datawindow painter.

2.Create a window object using the window painter.  Add a datawindow control to the window object.  Associate the datawindow object you created with the datawindow control (do this by clicking on the datawindow control and entering the datawindow object name on the properties tab under "DataObject".)

3. Ok, you probably did all that already.  Now a couple things that you may not have done.  First, you need to make sure the application is connected to the database.  You can do this in the application's "open" event.  We'll use the default transaction object - called SQLCA - to connect to the database.  You may get away with just the following command (in the app open event) :

CONNECT USING SQLCA;  

-or- you may need to set some parms before connecting, such as :

// Profile ID2
SQLCA.DBMS = "O73 ORACLE 7.3"
SQLCA.LogPass = <***>
SQLCA.ServerName = "whatever"
SQLCA.LogId = "whatever"
SQLCA.AutoCommit = True

CONNECT USING SQLCA

but DON'T PANIC!  If the simple CONNECT USING SQLCA" command doesn't work for ya, I've got an easy way to get those parameters without going nuts!  To sum up, add the following code to your application's "open" event :


CONNECT USING SQLCA
IF SQLCA.SQLCode <> 0 THEN
          MessageBox("Connect Failed", &
               "Cannot connect to database " &
               + SQLCA.SQLErrText)
END IF


4. Ok, now that we have a window with a datawindow control attached and a connection to the database, we can get down to business.  Before you can show data, you need to set a transaction object, which essentially attaches the database to the datawindow.  For your test, you can create a command button and put this code in the "clicked" event :

// Set the transaction object to SQLCA.
dw_1.SetTransObject(SQLCA)

// And now you can retrieve the data
dw_1.Retrieve()


-- Note I assume that you named your datawindow control "dw_1".  If not, substitute the name of your datawindow control for dw_1 (IMPORTANT - NOT THE DATAWINDOW OBJECT NAME! )


Ok, this is a start for ya - let me know how you make out !

-- Bill

Avatar of DrVannacult

ASKER

Ok, thanks ya for ur comments

I've did it with

//Begin
CONNECT USING SQLCA;
IF SQLCA.SQLCode <> 0 THEN
         MessageBox("Connect Failed", &
              "Cannot connect to database " &
              + SQLCA.SQLErrText);
END IF
//End

In the Application's open events.
And the messagebox is appeared with message
"Cannot connect to database DBMS is not supported in your current installation."
So what's that means? Did my PB8 eval not properly installed? What should I do now? please guide me. 8)

Thanks for your comment,
drvannacult
I'll try to install PB8 again to try it while I'm waiting for your answers....

8)
respect to all expert!
OiC! Coooool
I can made it works now!
by COPY-'n-PASTE from DB Profile's Syntax to Script Editor.
It's look like these...

SQLCA.DBMS = "ODBC"
SQLCA.AutoCommit = False
SQLCA.DBParm = "ConnectString='DSN=TEST_PB;UID=;PWD=;'"
CONNECT USING SQLCA;
dw_myown.SetTransObject(SQLCA)
dw_myown.Retrieve()

It's worked right now! Thanks u much for guiding me to the star!
8)

Oh! But I have somethings to ask u before I give u all 50 points. What's about the .AutoCommit property? Why your code is set it to True but In the DB Profile's syntax It gonna be False.

Thanks again!
an expert...
drvannacult
If It possible, I have some more question to ask to u.
How can I manipulating my data in DataWindow?
Because the things I did above look like a read-only dataset. How can I make it editable,appendable also delete. Maybe I say about .InsertRow() but I thinks there is a better way to do these such things since I thinks It should be easier because PB is a Database-Application-IDE.(I thinks that's no-need to coding about Append,Delete,Edit anymore maybe It has an automatically method to do that.)

8)
Thanks very much,
If u can guide me again, I'll put the point to 75 or above! for u only one!
8)

drvannacult
I did it!
I need your help!
Thanks ya!

8)
drvannacult
Hi doc.  Glad I can help!  I'll do 1 at a time for you.

Autocommit : You can set Autocommit to TRUE or FALSE.

When you set Autocommit = FALSE, the Powerbuilder application performs a SQL BEGIN TRANSACTION as soon as the application opens and immediately after every commit.  This means that you always have a SQL transaction open while you are in your app.  The good thing about this is that you never need to worry about starting a transaction - you just need to commit or rollback.  The bad thing is that it leaves a transaction open at all times, and this can cause you database issues when you go to truncate a log or forget to commit.  The general consensus is that Autocommit=false is bas.

On the other hand, autocommit=true is good.  Left alone, it automatically commits your transaction as soon as you update (never hangs an open transaction.)  If you want to do a multi - table update, you can fire an explicit "BEGIN TRANSACTION" and do your own transaction handling.  This is the best way to go (just remember that Autocommit is false by default - you need to explicitly set it to true.)

Good question and good stuff to know - most PB newbies ignore this and regret it later on!




ASKER CERTIFIED SOLUTION
Avatar of pbguy
pbguy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
All works for me!!!
Met at the next time!
8)

Thanks u very much for ur guiding/help...
Thanks expert! I'm very happy for ur comments!
drvannacult
Sorry for lately accept!
8)

Thanks u much,
drvannacult