Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADOCommand HELP!!!!

Status
Not open for further replies.

memevertical2

Programmer
May 2, 2008
35
Hi everyone....I have a problem....I have my ADOQuery and I have a DBGrid, and a Dataset.....everything works great, I'm able to see on my DBgrid a selected table from a MDB file. But when I execute the following code, nothing happens:

ADOCommand1.CommandType := cmdText;
ADOCommand1.CommandText := 'INSERT INTO TABLE_1 (Title) VALUES ("Title Test")';
ADOCommAnd1.Execute;

I want to be able to insert information into the Table.

Thanks.
 
Perhaps try using a TADOQuery and call the .ExecSQL method to execute a SQL statement that doesn't return a result set.
 
I tried this, and same thing...nothing happens

ADOQuery1.Active:=false;
ADOQuery1.SQL.Clear;

ADOQuery1.SQL.Add('INSERT INTO LISTINGS (Title)');
ADOQuery1.SQL.Add('VALUES ("Title Test")');
ADOQuery1.ExecSQL;

what can be going wrong?
 
Give this a try...

ADOQuery1.SQl.Add('Insert into Listings (Title)');
ADOQuery1.SQL.Add('Values('+QuotedStr('Title Test')+')');
ADOQuery1.ExecSQL;

or

ADOQuery1.SQL.Add('Insert into Listings (Title)');
ADOQuery1.SQL.Add('Values :)X1)');
ADOQuery1.SQL.Params.ParamByName('X1').AsString:='Title Test';
ADOQuery1.ExecSQL;
 
Thanks Tony, let me tell you what happened.

The first code compiles good, but when executed, it give an error: Syntax error in FROM class.

The second one, I saw that ADOQuery1.SQL.Params doesnt exist, SQL doesnt have the Params thing.....

any other ideas? Thanks a lot for your help.
 
try this and see if the query is actually correct, there is no FROM clause in your INSERT query!
Code:
uses Dialogs;

ADOQuery1.SQl.Add('Insert into Listings (Title)');
ADOQuery1.SQL.Add('Values('+QuotedStr('Title Test')+')');
[b]ShowMessage(ADOQuery1.SQL.Text);[/b]
ADOQuery1.ExecSQL;

should show you a message box with the SQL that you are about to execute. Check it and make sure it's correct.

Leslie

Have you met Hardy Heron?
 
Thanks Leslie,

It shows the same error, and I also noticed something strange, when the first line runs, the DBGrid that displays the data goes blank, like if it disconnects.
 
Did it show you a messagebox with the SQL in it? is it a valid SQL? Is it:
[tt]
INSERT INTO Listing (Title) VALUES ('Title Test')[/tt]

or did the message box have some other SQL statement?
 
Yes, it shows that in a dialog. But the Grid displaying the info goes blank.
 
Cool...it works....let me ask you something....the table is a little big, so loading it takes some seconds, and the refresh took even longer...any way to make that waiting time faster?
 
Wait, one more question....how can I have two DBGrids, each one connected to a different table at the same time? or 3 or 4?

Thanks Leslie :)
 
just set the datasource of each dbgrid to the dataset of the table you want it to show.

So you would need to drop the table onto the datamodule, drop a dataset and connect that to the table and connect the dbgrid datasource to the dataset...

(I think those are all the correct names and connections...I don't have Delphi open in front of me and I'm trying to pull it all out of my head!)

HTH
Leslie
 
Hey Leslie, on quick question.....if you have a table open, with 2 fields, a code and a text, and using the code I need to find out the text that goes with that code, how can I retrieve that? I was performing a sql "SELECT FROM WHERE" but that seems wrong....how can I do it more efficient?

Thanks for all your help my friend....
 
If you have the recordset that you want to search already loaded in memory you can use the .locate method. Otherwise, if you do have to search, you can use your SELECT x FROM y WHERE z. If you plan to do a lot of searching on that code you might consider creating a prepared query and use a parameter. It can speed things up depending on the database.
 
Well, this is the case. I have 2 querys open, LIST_ITEMS and LOCATIONS, LIST_ITEMS has many fields but one of them is LOCATION_ID, and the LOCATIONS Table has 2 fields (LOCATION_ID, LOCATION_NAME)..... so, when I'm reading all the fields in LIST_ITEMS, the moment I reach to the location ID, I want to use that number to retrieve the location name from the LOCATIONS table..... the 2 tables are open in each query.

any ideas on how to retrieve that?

Thanks....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top