New Features of JSM sqlhelper 2.0 (C #)

Source: Internet
Author: User
ArticleDirectory
    • Execute SQL statements
    • Tableframework implements simple data insertion and update

This article mainly introduces the features and usage of the new version of JSM sqlhelper2.0!

New Features of JSM sqlhelper2.0
    1. Inherit the static method mode of the original sqlhelper and optimize it.

    2. Enhance web. config configuration support to facilitate routine website maintenance.

    3. Added the facial object class. You can use the sqlhelper object to easily implement complexProgramLogic.

    4. Added support for access, Oracle, and MySQL databases.

    5. Added the tableframework class to implement simple insert and update statements, automatically generate parameters and SQL statements, and reduceCodeQuantity.

JSM sqlhelper configuration method

Open the Web. config file and configure the Add item in configurationsettings under the configuration node. The name indicates the default read link address of the program.

Read from web. config. You can overwrite and use the method to pass in the Link string. The Web. config configuration instance code is as follows:

   <?  XML version = "1.0"  ?> 
< Configuration >
< Connectionstrings >
< Add Connectionstring = "Server =.; uid = sa; Pwd = ***; database = dbname" Name = "Sqlserverhelper" />
< Add Connectionstring = "Data Source = orcl; user id = system; Password = ***; Integrated Security = No" Name = "Oraclehelper" />
< Add Connectionstring = "Server = localhost; uid = root; Pwd = ***; database = mysql_dbname" Name = "Mysqlhelper" />
</ Connectionstrings >
< System. Web >
< Compilation Debug = "True" />
</ System. Web >
</ Configuration >
Static Implementation of JSM sqlhelper
     ///   <Summary>  
/// Read Student Information
/// </Summary>
Datatable readstudent ( Long Stid)
{
Return Sqlserverhelper. readtable (" Select * from [Students] Where stid = @ stid " ,
Sqlserverhelper. createinputparameter ( " @ Stid " , Sqldbtype. bigint, stid ));
}

/// <Summary>
/// Delete Student Information
/// </Summary>
Int Deletestudent ( Long Stid)
{
Return Sqlserverhelper. executenonquery ( " Delete from [Students] Where stid = @ stid " ,
Sqlserverhelper. createinputparameter ( " @ Stid " , Sqldbtype. bigint, stid ));
}
JSM sqlhelper face image object Implementation Method

In complex database operations, the face object method can execute multiple SQL code at a time by connecting to the database, thus improving the program execution efficiency.

Execute SQL statements
     ///   <Summary>  
/// Read Student Information
/// </Summary>
Datatable readstudent ( Long Stid)
{
Using (Sqlserverhelper helper =New Sqlserverhelper ())
{
Helper. Command. commandtext = " Select * from [Students] Where stid = @ stid " ;
Helper. addparameter ( " @ Stid " , Sqldbtype. bigint, stid );
Helper. open ();
Return Helper. readtable ();
}
}

/// <Summary>
/// Delete student information to implement transactions and execute the delete SQL statement
/// </Summary>
Int Deletestudent ( Long Stid)
{
Using (Sqlserverhelper helper = New Sqlserverhelper ())
{
Helper. open ();
// Start transaction
Sqltransaction TRAN = helper. Connection. begintransaction ();
Helper. Command. Transaction = Tran;
Try
{
Helper. Command. commandtext = " Delete from [Students] Where stid = @ stid " ;
Helper. addparameter ( " @ Stid " , Sqldbtype. bigint, stid );
Int R = helper. executenonequery ();
Tran. Commit ();
Return R;
}
Catch {
Tran. rollback ();
Throw ;
}
}
}
Tableframework implements simple data insertion and update

Using tableframework, you can use tameframework to add column and data value information. Using inserttable or updatetable, you can easily generate SQL statements and parameters, which are accurate and simple and easy to maintain in the future, add only one column value. The sample code is as follows:

     ///   <Summary>  
/// Add Student Information
/// </Summary>
Bool Insertstudent ( String Studentname, String Classname)
{
Tableframework TF = New Tableframework ( " Students " );
TF. Add ( " Student_name " , Studentname );
TF. Add ( " Class " , Classname );
Using (Sqlserverhelper helper =New Sqlserverhelper ())
{
Helper. open ();
// Insert a new record
Return Helper. inserttable (TF );
}
}
/// <Summary>
/// Update Student Information
/// </Summary>
Bool Updatestudent ( Long Stid, String Studentname, String Classname)
{
Tableframework TF = New Tableframework ( " Students " );
TF. Add ( " Student_name " , Studentname );
TF. Add ( " Class " , Classname );
Using (Sqlserverhelper helper = New Sqlserverhelper ())
{
Helper. addparameter ( " @ Stid " , Sqldbtype. bigint, stid );
Helper. open ();
Return Helper. updatetable (TF, " Where stid = @ stid " , False );
}
}

Download JSM sqlhelper 2.0 source code

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.