Data-tier development

Source: Internet
Author: User

The recent development of a news system;
The news system is a very simple thing;
Before using ASP to do development, these things, regardless of the interface, can basically say one day can be written out (of course also depends on the function and complexity of the degree of it)
In use. NET has not done much development; it can be said that the pursuit of the present is only a result;
As just beginning to learn, also can only pursue a result, first reach will use, regardless of efficiency and security, as long as the realization on the line;
Of course, this kind of thing to do is only for learning and communication use it, can not be used in business and web sites;
But as a novice, the general company will not let you write directly or use what you write out of the
All you have to do is to practise your skills first.
Oh ~ ~
This is just a database development, because you can use SQL statements and stored procedures at the same time, in the entire data layer, SQL or stored procedures in two ways to call; In this demo process, please give a lot of advice; NET development and three-tier architecture

Here's the code: using System;
Using System.Configuration;
Using System.Data.SqlClient;
Using System.Data;

Namespace Powerleader.components
... {
/**////<summary>
Data-tier base class
</summary>
public class DataBase
... {
Private SqlConnection myconnection;
Private CommandType Proccommandtype;

Public DataBase ()
... {
//
TODO: Add constructor logic here
//
}


Open&close Connection. Open Shutdown Database connection #region Open&close Connection. Turn off the database connection
/**////<summary>
Create and Open Connection generate a database connection
</summary>
private void Open ()
... {
if (myconnection = null)
... {
myconnection = new SqlConnection (configurationsettings.appsettings["connstring"));
Myconnection.open ();
}
}

/**////<summary>
Close Connection Closes the database connection
</summary>
private void Close ()
... {
if (myconnection!= null)
Myconnection.close ();
}
#endregion

Run stored procedure. Executes a stored procedure #region run stored procedure. Execute a Stored procedure
/**////<summary>
Run stored procedure. Execute a Stored procedure
</summary>
<param name= "procname" >name of stored procedure. Stored Procedure name </param>
<returns>stored procedure return value. Stored procedure returns </returns>
public int Runproc (string procname)
... {
SqlCommand cmd = CreateCommand (procname,null);
Cmd. ExecuteNonQuery ();
This. Close ();
return (int) cmd. parameters["@v_return"]. Value;
}

/**////<summary>
Run stored procedure. Execute a stored procedure or SQL statement
</summary>
<param name= "procname" >name of stored procedure. stored procedure name or SQL statement </param>
<param name= "PAMs" >stored procedure params. Stored Procedure Parameters </param>
<returns>stored procedure return value. Stored procedure returns </returns>
public int Runproc (string procname,sqlparameter[] pams)
... {
SqlCommand cmd = CreateCommand (procname,pams);
Cmd. ExecuteNonQuery ();
This. Close ();
return (int) cmd. parameters["@v_return"]. Value;
}

/**////<summary>
Run stored procedure. Execute a Stored procedure
</summary>
<param name= "procname" >name of stored procedure. Stored procedure name or SQL statement </param>
<param name= "DataReader" >return result of procedure. Stored Procedure return value </param>
public void Runproc (string procname,out SqlDataReader DataReader)
... {
SqlCommand cmd = CreateCommand (procname,null);
DataReader = cmd. ExecuteReader (System.Data.CommandBehavior.CloseConnection);
}

/**/

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.