[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

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
0
ST3VO
Asked:
ST3VO
  • 12
  • 2
  • 2
  • +3
1 Solution
 
TheRealLokiSenior DeveloperCommented:
does "AsciiDataset" allow you to apply an Index?
 that would effectively sort your grid
0
 
ST3VOAuthor Commented:
No it doesn't :o(
0
 
JohnjcesCommented:
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
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
ST3VOAuthor Commented:
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
0
 
ST3VOAuthor Commented:
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!

0
 
ST3VOAuthor Commented:
If I try to use the Tablename on the query I get:

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

0
 
JohnjcesCommented:
Hmmm.  I don't know!

Sorry I couldn't help.

John
0
 
ST3VOAuthor Commented:
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?
0
 
kretzschmarCommented:
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 ;-)
0
 
diniludCommented:
i am not familiar with TAsciiDataset .
i saw it's demo version.

Why can't you use it's 'OrderBy' property
0
 
ST3VOAuthor Commented:
Well, I cannot use the OrderBy property because I need to be able to perform more details queries, not just orderng :o/
0
 
ST3VOAuthor Commented:
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
0
 
diniludCommented:
Connect a clientdataset to the  AsciiDataset using a datasetprover.

The saving have only some issue.
Soring,Filtering,display etc are eassy.
0
 
ST3VOAuthor Commented:
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
0
 
spk2000arCommented:
You can try wth TAdvStringGrid from TMS Software... or may be an extension of it TAdvSpreadGrid that works natively with CSV files.
That's a great component.
Try it. I think this is something like you need.
0
 
ST3VOAuthor Commented:
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/

0
 
spk2000arCommented:
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.
0
 
ST3VOAuthor Commented:
Has the trial got any restrictions?
0
 
ST3VOAuthor Commented:
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!

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

  • 12
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now