点击(此处)折叠或打开
- using System;
- using System.Data;
- using System.Text;
- using System.Configuration;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using MySql.Data.MySqlClient;
- //☆qau 555 2015.11 博盈杯
- namespace DB_
- {
- public class DB
- {
- public DB()
- {
- // 在此处添加构造函数逻辑
- }
- public MySqlConnection conntent()
- {
- string constr = "Data Source=127.0.0.1;port=3306;Database=test;User Id=root;Password=root;CharSet=utf8;allow zero datetime=true";
- MySqlConnection con = new MySqlConnection(constr);
- try
- {
- con.Open();
- return con;// 成功
- }
- catch (Exception ex)
- {
- return null;//连接打开出现异常
- }
- }//连接字符串,返回MySqlConnection 链接对象
- public DataSet Select(string sqlstr)//返回一个DataSet数据集或NULL
- {
- MySqlDataAdapter myadapter = new MySqlDataAdapter(sqlstr, conntent());
- DataSet select = new DataSet();
- int suc_count = myadapter.Fill(select);
- if (select != null) { return select; }
- else { return null; }
- }
- public MySqlDataReader Select1(string sqlstr)//返回一个MySqlDataReader对象,或null
- {
- MySqlCommand mycmd = new MySqlCommand(sqlstr,conntent());
- try
- {
- MySqlDataReader select1 = mycmd.ExecuteReader();
- if (select1 != null){ return select1; }
- else { return null; }
- }
- catch (Exception ex)
- {
- return null;
- }
- }
- public bool ZSG(string sqlstr)//根据传人的sqlstr 和 连接对象,执行操作
- {//调用ZSG()函数进行增删改的操作,成功TRUE,失败FALSE
- MySqlCommand mycmd = new MySqlCommand(sqlstr, conntent());
- try
- {
- if (mycmd.ExecuteNonQuery() > 0)
- { return true;//成功 }
- else
- { return false; }
- }
- catch{ return false; }
- }
- }
- }