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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delphi Programming with SQL Server As Back End

Status
Not open for further replies.

pro2003

Programmer
Apr 25, 2003
3
US
hi,
I have created an application with SQL Server as back end. Once I tried to save in a speciufic table it says "Conncetion Faliure". Where as in all other tables it saves fine. This is the code where the error occurs:

Code:
TADODataSet(Dataset).CommandText := Format('Select * From %s Where (%s=%d) and (%s=%d)',[TableName, IDFieldName, NoID, StoreIDFieldName, 0]);
      try
        Dataset.Open;// This is where error occurs....
      except
        ErrorMsg('Error Opening Table with Command: %s',[TADODataset(Dataset).CommandText]);
        raise;  // re-raise the exception

Thanks for your help in advance. :)
 
Hi,
I usually use TAdoDataset.TableName
or
TAdoQuery.Active:=False;
TAdoQuery.Sql.Clear;
TAdoQuery.Sql.add('Select * From '+SomeTableName );
TAdoQuery.Sql.add('Where SomeField='''+SomeString+'''');
TAdoQuery.Active:=True;

and it works.

Ciao,
Geppo Darkson.
 
Hello Pro2003



I do something similar...


query:='SELECT * FROM '+TableName+' '+
'WHERE '+IDFieldName+'='+inttostr(NoID)+' '+
'AND '+StoreIDFieldName+'=0';
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(query);
ADOQuery1.Open;

while (not ADOQuery1.Eof) do
begin
ListBox1.Add(ADOQuery1.Fields[0].AsString);
ADOQuery1.Next;
end;
ADOQuery1.Close;

David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top