Help Updating Database

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Pepe T
Posts: 2
Joined: Thu 28 Jun 2007 17:30

Help Updating Database

Post by Pepe T » Mon 09 Jul 2007 15:23

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

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Tue 10 Jul 2007 07:49

I noticed several mistakes in your code, but in general you chose the correcr approach. This code is correct:

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;
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.

Pepe T
Posts: 2
Joined: Thu 28 Jun 2007 17:30

Post by Pepe T » Tue 10 Jul 2007 18:38

Antaeus,
the table doesn't get updated. I trace the values with TMSSQL in debug Mode and the values passed are correct but no update happens.
Any suggestions are greatly appreciated.
Pepe

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Wed 11 Jul 2007 06:33

Did you try to execute the intercepted query using Query Analyser? What was the result?

Post Reply