展开全部
(1)首先需要下载C#访问MySQL数据库的ADO.NET驱动程序
mysql-connector-net-6.3.8.msi
(2)安装mysql-connector-net
然后直接在Windows操作系统安装 mysql-connector-net-6.3.8.msi
(3)封装32313133353236313431303231363533e58685e5aeb931333365656632数据库访问组件DbConnectionMySQL
/// /// MySQL数据库 /// 版本 mysql-connector-net-6.3.8.msi /// [Serializable] public class DbConnectionMySQL : DbConnectionWrapper { public DbConnectionMySQL(string pConnectionString) : base(pConnectionString) { this.m_dbconn = new MySqlConnection(pConnectionString); this.m_DbConnState = DbConnState.Free; } //-- public override DbDataAdapter GetDbDataAdapter() { return new MySqlDataAdapter(); } public override DbDataAdapter GetDbDataAdapter(DbCommand dbCommand) { return new MySqlDataAdapter(dbCommand as MySqlCommand); } public override DbCommand GetDbCommand() { return new MySqlCommand(); } public override DbConnection GetDbConnection() { return new MySqlConnection(); } public override DbCommandBuilder GetDbCommandBuilder() { return new MySqlCommandBuilder(); } public override DataProviderType GetCurrentDataProviderType() { return DataProviderType.Sql; } public override bool IsExistsTable(string TableName, string UserName) { #region information bool rbc = false; //TABLES表中去查询 table_name string dSql = "select * from TABLES where table_name='" + TableName + "'"; DataSet ds = this.ExecuteDataSet(dSql); if (ds != null) { if (ds.Tables[0].Rows.Count > 0) { rbc = true; } else { rbc = false; } } else { rbc = false; } return rbc; #endregion } public override bool IsExistsField(string FieldName, string TableName) { #region information bool rbc = false; string dSql = ""; dSql = "select * from " + TableName + " where 1<>1"; DataSet ds = this.ExecuteDataSet(dSql); if (ds != null) { DataTable dt = ds.Tables[0]; for (int j = 0; j < dt.Columns.Count; j++) { if (dt.Columns[j].ColumnName.ToString().ToUpper() == FieldName.ToString().ToUpper()) { rbc = true; goto Return_End; } } dt.Dispose(); dt = null; } ds.Dispose(); ds = null; Return_End: return rbc; #endregion } public override char ParameterChar { get { return ':'; //SQLite的参数符号为: } } public override DbParameter CreateParameter(string name, object value) { return new MySqlParameter(name, value); } public override DbParameter CreateParameter(string name) { DbParameter dbp = new MySqlParameter(); dbp.ParameterName = name; return dbp; } public override DbParameter CreateParameter(string name, DbType dbtype, object value) { DbParameter dbp = new MySqlParameter(); dbp.ParameterName = name; dbp.Value = value; dbp.DbType = dbtype; return dbp; } public override DbParameter CreateParameter(string name, DbType dbtype, int size, object value) { DbParameter dbp = new MySqlParameter(); dbp.ParameterName = name; dbp.Value = value; dbp.DbType = dbtype; dbp.Size = size; return dbp; } }
本回答由网友推荐
已赞过
已踩过<
你对这个回答的评价是?
评论
收起