ADO. NET generic database category, general database ado.net

Source: Internet
Author: User

ADO. NET generic database category, general database ado.net

The examples in this article share the ADO. NET generic database category for your reference. The details are as follows:

Using System; using System. collections. generic; using System. linq; using System. text; using System. threading. tasks; using System. data; using System. data. sqlClient; namespace Test {public class DBHelper {public static string ConString = "Data Source = .; initial Catalog = bankdb; User id = sa; Password = 123; "; // run the add, delete, and modify public static int RunNoQuery (string plain text, CommandType primitive type, params SqlParameter [] pars) method) {SqlConnection con = new SqlConnection (ConString); con. Open (); SqlCommand cmd = new SqlCommand (plain text, con); cmd. CommandType = parallel type; if (pars! = Null & pars. length> 0) {foreach (SqlParameter p in pars) {cmd. parameters. add (p) ;}} int rows = cmd. executeNonQuery (); con. close (); return rows;} // The public static DataSet RunSelect (string plain text, CommandType limit type, params SqlParameter [] pars) method for executing the query (DataSet) {SqlConnection con = new SqlConnection (ConString); SqlDataAdapter da = new SqlDataAdapter (plain text, con); da. selectCommand. commandTy Pe = partition type; if (pars! = Null & pars. length> 0) {foreach (SqlParameter p in pars) {da. selectCommand. parameters. add (p) ;}} DataSet ds = new DataSet (); da. fill (ds); return ds;} // obtain the value of public static object RunOneValue (string plain text, CommandType primitive type, params SqlParameter [] pars) by executing the query) {SqlConnection con = new SqlConnection (ConString); con. open (); SqlCommand cmd = new SqlCommand (plain text, con); cmd. commandType = cmdT Ype; if (pars! = Null & pars. length> 0) {foreach (SqlParameter p in pars) {cmd. parameters. add (p) ;}} object obj = cmd. executeScalar (); con. close (); return obj ;}}}

The above is all the content of this article, hoping to help you learn.

Articles you may be interested in:
  • Mysql database category
  • SQL Database Connector class encapsulated by ASP. NET
  • Guide to enabling external access settings for linux mysql Databases
  • C # how to access the PostGreSQL database
  • How to solve the problem that the SQL Server database becomes inaccessible to a single user
  • Summary of how to set remote access permissions for MySQL Databases
  • Multiple methods for setting remote database access for mysql
  • Python analyzes Nginx access logs and saves them to MySQL database instances.
  • C # Write high-concurrency Database Control Access Code
  • ASP. NET generic database category for SQLServer

Related Article

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.