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