Delphi 7 directly execute the SQL script file in the program

Source: Internet
Author: User

In the process of MSDE operations. Execute some SQL scripts. Some are from
The SQL statement generated in SQL Server 2000 is a suffix script. There is no Enterprise Manager in MSDE,
All operations are completed in the program. Use the following functions to execute SQL scripts.

// Execute an SQL file. The file can only be ANSI encoded.
// If the file is unicode encoded, it will be garbled.
VaR
S: string;
Sqltext: string;
Sqlfile: textfile;
Begin
If opendialog1.execute then
Begin
Assignfile (sqlfile, opendialog1.filename );
Filemode: = 0;
Reset (sqlfile );
Try
Adoconnection1.begintrans;
While not EOF (sqlfile) Do
Begin
Readln (sqlfile, S );
Sqltext: = s;
While (not EOF (sqlfile) and
(Uppercase (TRIM (s) <> 'Go') Do
Begin
Readln (sqlfile, S );
If (uppercase (TRIM (s) <> 'Go') then
Sqltext: = sqltext + ''+ S;
End;
Adoquery1.close;
Adoquery1. SQL. Clear;
Adoquery1. SQL. Add (sqltext );
Adoquery1.execsql;
End;
Closefile (sqlfile );
Adoconnection1.committrans;
Application. MessageBox ('SQL corner finished! ',
'Hprompt ', mb_ OK + mb_iconinformation );
Except
Raise exception. Create ('SQL corner execution failed! ');
Adoconnection1.rollbacktrans;
End;
End;
End;

Adoconnection1, adoquery1, and opendialog1 are controls placed in the window. You can set it as a local variable to create and destroy it in this function.

20:03:52

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.