Link to home
Start Free TrialLog in
Avatar of ST3VO
ST3VOFlag for United Kingdom of Great Britain and Northern Ireland

asked on

SQL Query on DGrid Problem

Hi all,

I am using AsciiDataset to read and write from CSV files.

This is a really strange question but I need to sort/perform search on a DBGrid without using a TQuery.

The Reason? Well TQuery asks for a Database name and I am using these components so I cannot put TheFile.csv as the Database name because it doesn't support it.

I've got the DBGrid connected to the data already but I need to perform some Queries.

Is there anyway around this please?

No DNS Please! I really want to avoid that and keep it as the LAST resort :o)

Thanks

ST3VO
Avatar of TheRealLoki
TheRealLoki
Flag of New Zealand image

does "AsciiDataset" allow you to apply an Index?
 that would effectively sort your grid
Avatar of ST3VO

ASKER

No it doesn't :o(
I may be confused and way off base by what you're doing or wanting, but ...

you could run a TQuery (you said you didn't want to, but... (another but!)) by connecting a TQuery to the already existing DataSource that your grid is connected to. No need for a database name.

You could sort select do everything needed against the already appearing data in the grid via the new TQuery connected to the datasource..

John
Avatar of ST3VO

ASKER

I have tried but I cannot set to TQuery to active as it tells me that the Table does not exists?

Any ideas why?

Thanks

ST3VO
Avatar of ST3VO

ASKER

Another thing is that the Component is using the Tablename as data.csv - A CVS File.

If I do a SELECT * From ....From where do I specify? I cannot use FROM data.csv!

Avatar of ST3VO

ASKER

If I try to use the Tablename on the query I get:

Error "Queries on text or ascii tables is not supported"

Hmmm.  I don't know!

Sorry I couldn't help.

John
Avatar of ST3VO

ASKER

I've already paid for this component but I'm willing to go for any other if I can do both CSV plus Queries!

Anyone know of any components that can do this pls?
hmm,

i would read the csv file in some kind from memory-dataset (clientdataset for ex.)

or
http://www.torry.net/pages.php?id=567

or
http://www.torry.net/pages.php?id=567

btw.

if using bde, just define a schema-file --> see bde-help

meikl ;-)
i am not familiar with TAsciiDataset .
i saw it's demo version.

Why can't you use it's 'OrderBy' property
Avatar of ST3VO

ASKER

Well, I cannot use the OrderBy property because I need to be able to perform more details queries, not just orderng :o/
Avatar of ST3VO

ASKER

Hi kretzschmar,

I've checked out most the those components already and they all seem to do more or less the same thing...Connect to the table directly by filename...which is ok but leave a problem when to do SQL Queries!

I might be going to wrong road here....I'll post it out (what I need to do):

1. Start Application
2. Import CSV File   (ID, Description, Price, Colour, Make, etc...)
3. User Searches (TQuery)
4. Search is for example (Search * RED Cars) - order by the search results first

Now is part 2...(Create a new ID Column)

5. Replace the ID field with a new order and ID Number 1.to end of count ASC order.

6. Save to CSV File.

7. End.

I know it might look strange what I'm trying to do here but it's for a reason.

So I basically import a csv...query it...re-order it by search results....create a new ID column...save it back!

Anyone know the best way to get this done?

Thanks

ST3VO
Connect a clientdataset to the  AsciiDataset using a datasetprover.

The saving have only some issue.
Soring,Filtering,display etc are eassy.
Avatar of ST3VO

ASKER

I wrote to the creators of the component and they told me that it cannot be done with their component.

Although you have a point (dinilud), I am now looking for an alternatinve way of doing this ...current trying out with a listview with which I have managed to get nearly working but having a problem when saving it.

It is saving the header but not the subitems to a newly inserted column :o/

I'm using TAdvListView for saving the listview to csv but no luck saving the NEW Column ...just the header :o/

In case you can help...here is the Saving Code:

//Load the CSV
 ListView1.LoadHeader:=True;
 ListView1.LoadFromCSV('data.csv');

//ADD the New Column and populate it
procedure TForm1.AddColumnClick(Sender: TObject);
var
      newCol: TListColumn;
      z,j : integer;
      existItem: TListItem;
begin
      listview1.items.beginupdate;
      j:=0;

        //if ID Column already exists then exit
       if ListView1.Columns.Items[j].Caption =('ID') then exit;

       //add a dummy ID column
      ListView1.Columns.Insert(0);
      ListView1.Columns.Items[j].Caption :=('ID');

    for z := 0 to (ListView1.Items.Count-1) do begin
            existItem.SubItems.Add( IntToStr(ListView1.Items[z].Index+1) );
            listview1.items.endupdate;

   end;
end;

As I said before, it look fine on the ListView but the Subitems are not being saved :o/

Any ideas?

Thanks

ST3VO
ASKER CERTIFIED SOLUTION
Avatar of Martin Barreda
Martin Barreda
Flag of Argentina image

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
Avatar of ST3VO

ASKER

Thanks I will give it a try.

Do you think that you can help me on the previous post?

I've got a Column with subitems that I need to replace, I just cannot get it to work.

Right now it's working but on the wrong column :o/

Could you please check the code below?

///////////////////////////////////////////////////////////////////
//  CODE
//////////////////////////////////////////////////////////////////
procedure TForm1.Button12Click(Sender: TObject);
var
      newCol: TListColumn;
      z,j : integer;
      existItem: TListItem;
begin

 
      ListView1.Columns.insert(0);
   

      //Now insert the numbers

      for z := 0 to (ListView1.Items.Count-1) do begin
            //find the current item in the list
            existItem := ListView1.Items[z];
            existItem.SubItems.Insert(0, IntToStr(ListView1.Items[z].Index) );

    end;
end;

Right now it is populating the second column with numbers 1 to listview items count ...but I need it to replace index 0 ...The first Column instead of the second one. I just cannot see where I'm going wrong :o/

I am really has no experience working with ListViews... the code it produce is too complex for every simple task you need.
I can't help you with them.
Everything that can be done with a ListView can be done with AdvStringGrid (and MUCH more)... so i don't even try them.
Avatar of ST3VO

ASKER

Has the trial got any restrictions?
Avatar of ST3VO

ASKER

I downloaded AdvStringGrid + the demos...installed it and I couldn't compile.

I checked for the FAQ's on the creator's website and there are issues if you have Full versions installed and try out trials.

In other words. Because I have a licenced TADVListView installed I cannot compile the trial of AdvStringGrid, so I cannot test it out without uninstalling the Full version of ADVListView first.

It's a known issue :o/

I don't want to buy the component without first trying it!

Avatar of ST3VO

ASKER

Great Components at TMS. I bought the whole pack!!! :o)