?
Solved

What is the best way to show records in dbgrid, do sql query and modify the records?

Posted on 2001-07-20
9
Medium Priority
?
256 Views
Last Modified: 2010-04-06
Hi all,
I have an event database.
When user open the mainform, I want all the records show in a "dbgrid". Then the user can select some conditions to do a sql query, the query result show in the "dbgrid", and they can modify some fields.

What is the best way to do that? What is the best component to do that? Please give me some
advice.  Thanks.

(I found a component, it name is xRxDBGrid. xSortRxDBGrid is an RxDBGrid (from RxLib) with automatically data sorting when user clicks on field's title button. Support for TRxQuery and
TTable-based grids.   http://deks.webjump.com/)

Regards, supwang
0
Comment
Question by:SupWang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6302908
hi supwang,

use the TUpdateSQL-Component as Update-Object of your TQuery (property UpdateObject)
fill out the the Update, Insert, Delete Statements in TUpdateSQL
(there is an expert, if you double click on it)
set the cachedupdates property to true of the TQuery
don't forget to call applyupdates, maybe in the afterpost and afterdelete-event of the TQuery

meikl ;-)
0
 
LVL 3

Expert Comment

by:ahll
ID: 6303860
Hi,

You can use a TTable component and the filter property, if you filter the table the grid relationed to its datasource will show only the records that applies this filter.

please excuse my english.

bye  
0
 
LVL 2

Author Comment

by:SupWang
ID: 6304036
Hi meikl,
I am not go to here for a long time. Your points stride over rwilson now. :-)
I will view the help of TUpdateSQL-Component. Please give me more advice.  

Hi ahll,
I want to use sql. Because the query will be very complicated, and may have many records.

Regards, supwang
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Accepted Solution

by:
ITugay earned 400 total points
ID: 6304542
Hi SupWang,

meikl :)

easy way to modify SQL statement is:

procedure TForm1.Query1BeforeOpen(DataSet: TDataSet);
var
  S: string;
begin
  S := 'select * from groups where group_name like "E1%" and user_name like "E2%"';
  S :=  StringReplace(S,   'E1',  Edit1.Text, [rfReplaceAll]);
  S :=  StringReplace(S,   'E2',  Edit2.Text, [rfReplaceAll]);
  Query1.SQL.Text := S;
end;

if user type nothing in TEdit1 then all recods will be shown. If user type some text then after reopenning Query1, dbgrid will keep only records where field "group_name" starts from typed text.

------
Igor
0
 
LVL 3

Expert Comment

by:rondi
ID: 6304615
You can use a regular TQuery and TDBGrid/TRxDBGrid.
The TQuery's RequestLive property should be set to True to let
users modify the data.
Then use queries with parameters
 eg.
const
  AT_LEAST_QUERY = "SELECT * FROM MyTable WHERE MyAmount >= :pAmount"

Then when the user exits the TEdit or clicks a "Filter"
button:

with Query1 do    //where Grid's datasource is Query1
begin
  DisableControls;
  try
    if Active then Close;  
    SQL.Clear;
    SQL.Add(AT_LEAST_QUERY);
    ParamByName("pAmount").AsInteger := StrToInt(Edit1.Text);
    Open;
  finally
    EnableControls;
  end;
end;

//-------------------------------------------------

This approach works for me. I just declare all this query
constants and fill the parameters later with whatever I want. The queries can get as complex as you want. I've
had a few with multiple nested SELECT's
eg. SELECT ... WHERE ... IN (SELECT ... WHERE ... IN (SELECT ... WHERE ... = ...))

All you really need to be wary of is the parameter types
so you use the right As... property, esp. with dates.

HTH,
rondi
0
 
LVL 2

Author Comment

by:SupWang
ID: 6304804
Hi meikl,
About the TUpdateSQL, it seems that it just be use when cached updates are enabled. But I don?t need to set the cached updates to true. How about I just set the TQuery's RequestLive property to True?

Hi Igor,
I like your comment. :-)  


Please give more advice.

Thanks, supwang
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6304954
yup, TUpdateSQL do only work,
if the TQuery cached updates are set,
but this may not cause a problem

the requestlive Porperty may not work under some conditions,
which depends on the database, which is used

meikl ;-)
0
 
LVL 2

Author Comment

by:SupWang
ID: 6343284
Hi,
Sorry, very busy in this time.
Thanks all.
0
 
LVL 2

Author Comment

by:SupWang
ID: 6678550
Hi meikl,
What time will need the TUpdateSQL?
If I just use some simple Query and the requestlive property can be true then I don't need the TUpdateSQL. Is it?
And could you give me a very simple example about the TUpdateSQL? (Please don't let me to view the delphi demo)

Regards, supwang
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month10 days, 8 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question