I'm using Delphi 2006 and SDAC for SQL 2000 v4.00.0.4
I run a TMSQuery that returns data to a grid from 2 tables for viewing only.
If data needs to be updated, on one table only, a Execute a TMSSQL with the following code in the SQL property of the TMSSQL:
Use LamTest
Update OpenJob
Set SalesmanN = :SalesmanN
where
SalesManN = :SalesmanNB
then call it like this:
MSQuery1.Close;
with MSSQL1 do
begin
Close;
Prepared;
Params[0].value := StrToInt(Edit1.Text);
Params[1].value := StrToInt(Edit2.Text);
Execute;
But it doesn't update anything. If I use SQL Analizer and run the SQL code there it works.
I'm using the right components? How do I update records, from one to hundreds?
Thanks
Help Updating Database
I noticed several mistakes in your code, but in general you chose the correcr approach. This code is correct:
If the result is the same, intercept the query that is sent to the server in any way (using Debug mode of TMSSQL, DBMonitor, or SQL Server Profiler). Try to run this query using SQL Server Query Analyzer, and check the result.
Code: Select all
var
par: TParam;
begin
with MSSQL1 do begin
MSSQL1.SQL.Text := 'Update LamTest.OpenJob Set SalesmanN = :SalesmanN where SalesManN = :SalesmanNB';
par := ParamByName('SalesmanN');
// ParamType and DataType should be explicitly assigned
par.ParamType := ptInput;
par.DataType := ftInteger;
par.AsString := Edit1.Text;
par := ParamByName('SalesmanNB');
par.ParamType := ptInput;
par.DataType := ftInteger;
par.AsString := Edit2.Text;
Prepared := True;
Execute;
end;
MSQuery1.Refresh;