DBHELP and SQL statements with things to deal with

Source: Internet
Author: User

DBHELP statements

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Data;usingSystem.Data.SqlClient;namespaceAnalog ATM Transfer {Static classDbhelp { Public Static BOOLIdubysql (stringSQL) {            BOOLFA =false; stringstr ="server=.; Integrated SECURITY=TRUE;DATABASE=BANKDB"; SqlConnection sqlconn=NewSqlConnection (str); SqlCommand Sqlcomm=NewSqlCommand (SQL, sqlconn); Try{sqlconn.                Open (); //Open TransactionSqlcomm. Transaction =sqlconn.                BeginTransaction (); FA= Sqlcomm. ExecuteNonQuery () >0?true:false; //Commit a transactionSqlcomm.Transaction.Commit (); }            Catch(SqlException ex) {//rolling back a transactionSqlcomm.            Transaction.rollback (); }            finally{sqlconn.            Close (); }            returnFA; }         Public StaticDataTable Gettablebysql (stringSQL) {DataTable Ta=NewDataTable (); stringstr ="server=.; Integrated SECURITY=TRUE;DATABASE=BANKDB"; SqlConnection sqlconn=NewSqlConnection (str); SqlCommand Sqlcomm=NewSqlCommand (SQL, sqlconn); SqlDataAdapter da=NewSqlDataAdapter (Sqlcomm); Da.            Fill (TA); returnTa; }    }}

SQL statements

--G. Transactions:--define the transfer transaction, and implement the transfer operation to test, note: During the transfer process is actually two transactions, one is "deposit", one is "withdraw", note the addition of transactions to the Transaction information tablebegin TranTran_bankDeclare @cou intSet @cou=0UpdateCardinfoSetBalance=Balance- the whereCardID='1010 3576 1234 5678'UpdateCardinfoSetBalance=Balance+ - whereCardID='1010 3576 1212 1134'Set @cou=@ @error+@couif(@cou<>0)    begin        rollback Tran--Roll back    EndElse    begin        Commit Tran        Insert  intoTransinfo (Cardid,transtype, Transmoney,remark)Values('1010 3576 1212 1134','deposited', -,'John Doe Deposit')        Insert  intoTransinfo (Cardid,transtype, Transmoney,remark)Values('1010 3576 1234 5678','withdrawal', the,'Zhang San withdrawal')        Print 'The transaction was successful to save the new data'    EndGo

DBHELP and SQL statements with things to deal with

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.