Solved

Executing SQL Querys in Code

Posted on 2014-02-11
2
266 Views
Last Modified: 2014-02-13
;
Is there  a simpler approach to updating a SQL Table than all this?  All this cross linkage of Transactions, Querys and Databases?  Do all Querys need transactions?

  IBDatabase1.DatabaseName := 'c:\backupdbs\JPBD.IB';
  IBDatabase1.Params.Clear
  IBDatabase1.Params.Add('user_name=sysdba');
  IBDatabase1.Params.Add('password=masterkey');

  IBDatabase1.DefaultTransaction := IBTransaction1;
  IBTransaction1.DefaultDatabase := IBDatabase1;

  IBQuery1.Transaction := IBTransaction1;

  IBDatabase1.Open;
  IBQuery1.Database := IBDatabase1;
  IBQuery1.SQL.Clear;
  IBQuery1.SQL.Add('Insert into Employee(PersonID, LastName) Values(1, ''Price'')');
  IBQuery1.Transaction.StartTransaction;
  IBQuery1.ExecSQL;
  IBQuery1.Transaction.Commit;
  IBDatabase1.Close;
0
Comment
Question by:CiaoBaby
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 69

Expert Comment

by:Qlemo
ID: 39851890
That again depends on the database system you are using. But most times you do not need transactions, which results in autocommiting all changes without chance to rollback changes.

Transactions are used to bundle several commands into a single "atomic" operation. They don't make much sense with a single command.
0
 
LVL 33

Accepted Solution

by:
ste5an earned 500 total points
ID: 39852631
The IB prefix sounds like FireBird. And yes, here you need explicit transactions. Well, abstraction is your friend. Encapsulate theses actions in an appropriate class model.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question