Board index » cppbuilder » TDBGrid Get Row; Set Row

TDBGrid Get Row; Set Row

Is there any function in DBGrid to...

  Get the current Row I am going to edit?
  Set the current Row that I want to edit?

I need to do this for a batch program that is Multi Threaded and will
be updating multiple rows at once.

 

Re:TDBGrid Get Row; Set Row


Hi, Robert!

Editing and row positioning are controlled by the data set, not the
grid. So long as the threads take the proper precautions (like
independent TSession, TDatabase and data set objects) then there should
be no problem. However, grids are only involved if they are displaying
data updated by the threads. In that case, the threads should notify the
main thread of the update so that it can refresh _its_ data set, which
it is displaying in the grid.

More on threads and databases can be found at

http://www.temporaldoorway.com/programming/cbuilder/databaseandbde/qu...

------
Mark Cashman, TeamB C++ Builder
http://www.temporaldoorway.com/programming/index.htm
C++ Builder, JBuilder programming information
Home of The C++ Builder Programmer's Webring - Join us!
------

Re:TDBGrid Get Row; Set Row


Quote
>>>>>>>>>>>>>>>>>> Original Message <<<<<<<<<<<<<<<<<<

On 3/17/2000, 11:37:48 AM, "Mark Cashman (TeamB)"
<markcash...@vtechnologies.com> wrote regarding Re: TDBGrid Get Row; Set
Row:

Quote
> Hi, Robert!
> Editing and row positioning are controlled by the data set, not the
> grid. So long as the threads take the proper precautions (like
> independent TSession, TDatabase and data set objects) then there
should
> be no problem. However, grids are only involved if they are displaying
> data updated by the threads. In that case, the threads should notify
the
> main thread of the update so that it can refresh _its_ data set, which
> it is displaying in the grid.
> More on threads and databases can be found at

http://www.temporaldoorway.com/programming/cbuilder/databaseandbde/quer
ythread.htm

How do I jump from row to row?

The only property I can see is ActiveRecord to get the active record
number, but its protected.  What property or method do I call to set
row 6 as the active record?

Re:TDBGrid Get Row; Set Row


TDataSet::RecNo .
Quote
Robert Piskac wrote:
> How do I jump from row to row?

> The only property I can see is ActiveRecord to get the active record
> number, but its protected.  What property or method do I call to set
> row 6 as the active record?

Re:TDBGrid Get Row; Set Row


Hi, Edward!

RecNo is not reliable. Only dBase and Paradox support it. The better
course is to either do a First() and then however many Next() you need
to the right row, or to use a bookmark, or to Locate on a specific
unique ID.

------
Mark Cashman, TeamB C++ Builder
http://www.temporaldoorway.com/programming/index.htm
C++ Builder, JBuilder programming information
Home of The C++ Builder Programmer's Webring - Join us!
------

Re:TDBGrid Get Row; Set Row


RecNo is always -1 with my database.  What is bad is that I have to
degrade my application to a bubble sort every time I want to update a
record.
I should be able to update the record like this.

li_retryCount =
DBGrid_devices->DataSource->DataSet->FieldByName("retry_count")->Row(
6)->AsInteger;

Does C++ Builder V5 have anything like this?

Quote
>>>>>>>>>>>>>>>>>> Original Message <<<<<<<<<<<<<<<<<<

On 3/20/2000, 1:27:54 PM, "Mark Cashman (TeamB)"
<markcash...@vtechnologies.com> wrote regarding Re: TDBGrid Get Row; Set
Row:
Quote
> Hi, Edward!
> RecNo is not reliable. Only dBase and Paradox support it. The better
> course is to either do a First() and then however many Next() you need
> to the right row, or to use a bookmark, or to Locate on a specific
> unique ID.
> ------
> Mark Cashman, TeamB C++ Builder
> http://www.temporaldoorway.com/programming/index.htm
> C++ Builder, JBuilder programming information
> Home of The C++ Builder Programmer's Webring - Join us!
> ------

Re:TDBGrid Get Row; Set Row


Hi, Robert!

There are no row numbers in relational databases, because ordering is
accomplished using indices on the database table (and that means when
you change the operative index, the row number of any particular row
changes). Finding a record depends on establishing one column as a
unique ID, on which you can use Locate (see Locate in the help). Data
aware controls like the grid automatically repoint the cursor
represented by their DataSource->DataSet to the record selected by the
user, so you can simply access the fields in the data set and be sure of
getting the current row.

Note that it is generally bad form to update through a control in BCB.
You should simply access the appropriate data set (preferably via a data
module), or its fields (preferably by persistent fields).

To get comfortable with the BCB way of doing things, you may want to
have a look at

    http://www.temporaldoorway.com/programming/cbuilder/basics/index.htm

which, among other things, includes "the simplest database program".

------
Mark Cashman, TeamB C++ Builder
http://www.temporaldoorway.com/programming/index.htm
C++ Builder, JBuilder programming information
Home of The C++ Builder Programmer's Webring - Join us!
------

Re:TDBGrid Get Row; Set Row


Quote
>>>>>>>>>>>>>>>>>> Original Message <<<<<<<<<<<<<<<<<<

On 3/21/2000, 3:00:32 PM, "Mark Cashman (TeamB)"
<markcash...@vtechnologies.com> wrote regarding Re: TDBGrid Get Row; Set
Row:

Quote
> There are no row numbers in relational databases, because ordering is
> accomplished using indices on the database table (and that means when
> you change the operative index, the row number of any particular row
> changes). Finding a record depends on establishing one column as a

There are row numbers in relational databases.  Oracle has row_id.
row_id is the unique identifier on all tables. There is even an index
on it.  Do a select row_id on table_name.  It works.  I can even
update a row using the row_id in an update statement.  So, your
statement of no row_id is not accurate.

Anyways, when I update a grid, I am updating data in memory and an
update statement is sent.  Rows should be available when working with
any grid.  Power builder has this syntax on a DBGrid

dw_employee.object.result[6] = "Updated";
This updates row 6 in the DBGrid in memory.  dw_empoyee.Update must be
performed to actually send the sql update command.

This is the same in C++ Builder.  I can cache updates then
applyUpdates and commit them to the database.

Most data controls are written for user interaction but I need to run
my C++ application in batch mode as well as having user interaction.  
My application will also be multithreaded which will result in
accessing multiple rows at any given time.  My problem is not updating
the database via the DBGrid control, but how to update the correct row
when I am done processing is the problem.  I do not use the DBGrid for
database updates.  I just read in the set of data I am processing and
display a result status on each row so the end user know my program is
working.

Example

Device    Password      Result
1234      A23456        Updated
12345     A23455        Bad Password

Re:TDBGrid Get Row; Set Row


Quote
>>>>>>>>>>>>>>>>>> Original Message <<<<<<<<<<<<<<<<<<

On 3/21/2000, 3:28:50 PM, Robert Piskac <rpis...@pbsoftware.com> wrote
regarding Re: TDBGrid Get Row; Set Row:

Quote
> >>>>>>>>>>>>>>>>>> Original Message <<<<<<<<<<<<<<<<<<
> There are row numbers in relational databases.  Oracle has row_id.
> row_id is the unique identifier on all tables. There is even an index
> on it.  Do a select row_id on table_name.  It works.  I can even
> update a row using the row_id in an update statement.  So, your
> statement of no row_id is not accurate.

Sorry that rowid not row_id.

Re:TDBGrid Get Row; Set Row


Hi, Robert!

The Oracle facility is highly non-standard and is not supported by
anyone else, so it is not wise to base your app on it. Relational theory
does not treat databases as ordered tables but as unordered sets. Even
indices are something of a corruption.

In any event, cached updates are transparent to the rest of the program.
Unlike what you describe for Powerbuilder, the VCL does not require you
to edit records through the grid in order to access the current record
or any other record. You can work with the database just as if you were
not using cached updates - in other words, access the fields in the
current row of the table / query and they will be the fields currently
shown on the current row of the grid. The user can do this as long as
they want and then you can apply updates.

The only time you need to care that you are using cached updates is when
you apply.

I'd recommend you get a copy of one of the excellent Learn C++ Builder n
in x days and a copy of  C++ Builder n Unleashed. Those should help you
understand a little more about how datasets work in BCB.

It's easier than I suspect you think. Don't be trapped by your knowledge
of previous tools.

------
Mark Cashman, TeamB C++ Builder
http://www.temporaldoorway.com/programming/index.htm
C++ Builder, JBuilder programming information
Home of The C++ Builder Programmer's Webring - Join us!
------

Other Threads