MYSQL C # General Class

Source: Internet
Author: User

Using System;

Using System.Collections.Generic;

Using System.Linq;

Using system.text;//Guide namespaces

Using System.Data;

Using MySql.Data.MySqlClient;

Using System.Configuration;

Namespace TEST.DAL.MYSQL

{

public class Dbhelp {private readonly string connstring = configurationmanager.connectionstrings["MySQL"]. ToString (); Private mysqlconnection mysqlconnection = null; Private Mysqlcommand Mysqlcommand = null; protected Mysqldatareader mysqldatareader = null; Private Mysqldataadapter mysqldataadapter = null; Private DataSet DataSet = null; private int i = 0; Private Mysqlconnection executemysqlconnection () {try {this.mysqlconnection = new mysqlconnection (this.connstring); This.mySqlConnection.Open (); } catch (Exception) {throw;} return this.mysqlconnection; } Private Mysqlcommand Executemysqlcommand (String sql,commandtype commandtype,mysqlparameter[] mysqlparameter) {try { This.mysqlconnection = this. Executemysqlconnection (); This.mysqlcommand = new Mysqlcommand (sql, this.mysqlconnection); if (mysqlparameter! = null && mysqlparameter.length > 0) {this.mySqlCommand.Parameters.AddRange ( Mysqlparameter); } This.mySqlCommand.CommandType = CommandType; } catch (Exception) {THrow; } return This.mysqlcommand; } protected Mysqldatareader Executemysqldatareader (String sql, CommandType commandtype, mysqlparameter[] Mysqlparameter) {try {This.mysqlcommand = this. Executemysqlcommand (SQL, CommandType, Mysqlparameter); This.mysqldatareader = This.mySqlCommand.ExecuteReader (); } catch (Exception) {throw;} return this.mysqldatareader; } protected DataSet ExecuteDataset (String sql, CommandType commandtype, mysqlparameter[] mysqlparameter) {This.dataset = New DataSet (); try {This.mysqlcommand = this. Executemysqlcommand (SQL, CommandType, Mysqlparameter); This.mysqldataadapter = new Mysqldataadapter (This.mysqlcommand); This.mySqlDataAdapter.Fill (DataSet); } catch (Exception) {throw;} return this.dataset; } protected int ExecuteScalar (String sql, CommandType commandtype, mysqlparameter[] mysqlparameter) {try {This.mysqlcomm and = this. Executemysqlcommand (SQL, CommandType, Mysqlparameter); this.i = Int. Parse (This.mySqlCommand.ExecuteScalar (). ToString ()); } catch(Exception) {throw;} return this.i; } protected int ExecuteNonQuery (String sql, CommandType commandtype, mysqlparameter[] mysqlparameter) {try {This.mysqlco Mmand = this. Executemysqlcommand (SQL, CommandType, Mysqlparameter); THIS.I = This.mySqlCommand.ExecuteNonQuery (); } catch (Exception) {throw;} return this.i; } protected void CloseConnection (Mysqlconnection mysqlconnection) {try {if (mysqlconnection! = null) {mysqlconnection = Null Mysqlconnection.close (); }} catch (Exception) {throw;}} protected void Closedatareader (Mysqldatareader mysqldatareader) {try {if (Mysqldatareader! = null) {Mysqldatareader = n Ull Mysqldatareader.close (); }} catch (Exception) {throw;}} }

}

MYSQL C # General Class

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.