/// <summary> /// 执行ExecuteReader操作,返回DataTable读取的数据集 /// </summary> /// <param name="ConnString">数据库连接字符串</param> /// <param name="dbname">表名</param> /// <param name="CmdType">指定如何解释命令字符串</param> /// <param name="CmdText">命令字符串</param> /// <param name="Parameter">参数列表</param> /// <returns></returns>yjyygyowxf207154 public DataSet ExtcuteDataSet(string ConnString, string dbname, CommandType CmdType, string CmdText, MySqlParameter[] Parameter, int CommandTimeout) { DataSet Ds = new DataSet(); MySqlConnection Conn = new MySqlConnection(ConnString); MySqlCommand Comm = new MySqlCommand(); if (CommandTimeout > 0) { Comm.CommandTimeout = CommandTimeout; } MySqlCmdHeader.CmdParameter(Comm, Conn, null, CmdType, CmdText, Parameter); MySqlDataAdapter Ap = new MySqlDataAdapter(); Ap.SelectCommand = Comm; try { if (!string.IsNullOrEmpty(dbname)) { Ap.Fill(Ds, dbname); } else { Ap.Fill(Ds, "db"); } } catch { } finally { Comm.Dispose(); Conn.Close(); Conn.Dispose(); } return(Ds); }
public string ExecuteScalar(string ConnString, CommandType CmdType, string CmdText, MySqlParameter[] Parameter, bool isTran) { string Sin = string.Empty; MySqlTransaction transaction; using (MySqlConnection Conn = new MySqlConnection(ConnString)) { if (Conn.State != ConnectionState.Open) { Conn.Open(); } transaction = Conn.BeginTransaction(); MySqlCommand Comm = new MySqlCommand(); MySqlCmdHeader.CmdParameter(Comm, Conn, null, CmdType, CmdText, Parameter); //Sin = Convert.ToString(Comm.ExecuteScalar()); try { Sin = Convert.ToString(Comm.ExecuteScalar()); transaction.Commit();//提交事务 } catch (Exception ex) { try { transaction.Rollback();//回滚事务 } catch (Exception ex2) { } } Comm.Dispose(); } return(Sin); }
public int ExecuteNonQuery(string ConnString, CommandType CmdType, string CmdText, MySqlParameter[] Parameter, bool isTran) { int Sin = 0; MySqlTransaction transaction; using (MySqlConnection Conn = new MySqlConnection(ConnString)) { if (Conn.State != ConnectionState.Open) { Conn.Open(); } transaction = Conn.BeginTransaction(); using (MySqlCommand Comm = new MySqlCommand()) { MySqlCmdHeader.CmdParameter(Comm, Conn, null, CmdType, CmdText, Parameter); try { Sin = Comm.ExecuteNonQuery(); transaction.Commit();//提交事务 } catch (Exception ex) { try { transaction.Rollback();//回滚事务 } catch (Exception ex2) { } } } } return(Sin); }
/// <summary> /// 执行无返回ExecuteNonQuery操作 /// </summary> /// <param name="ConnString">数据库连接字符串</param> /// <param name="CmdType">指定如何解释命令字符串</param> /// <param name="CmdText">命令字符串</param> /// <param name="Parameter">参数列表</param> /// <returns></returns> public void ExecuteNonQueryNull(string ConnString, CommandType CmdType, string CmdText, MySqlParameter[] Parameter) { using (MySqlConnection Conn = new MySqlConnection(ConnString)) { using (MySqlCommand Comm = new MySqlCommand()) { MySqlCmdHeader.CmdParameter(Comm, Conn, null, CmdType, CmdText, Parameter); Comm.ExecuteNonQuery(); Comm.Dispose(); } } }
/// <summary> /// 执行ExecuteReader操作,返回SqlDataReader读取的数据集 /// </summary> /// <param name="ConnString">数据库连接字符串</param> /// <param name="CmdType">指定如何解释命令字符串</param> /// <param name="CmdText">命令字符串</param> /// <param name="Parameter">参数列表</param> /// <returns></returns> public MySqlDataReader ExtcuteReader(string ConnString, CommandType CmdType, string CmdText, MySqlParameter[] Parameter) { MySqlConnection Conn = new MySqlConnection(ConnString); MySqlCommand Comm = new MySqlCommand(); MySqlCmdHeader.CmdParameter(Comm, Conn, null, CmdType, CmdText, Parameter); MySqlDataReader Dr = Comm.ExecuteReader(CommandBehavior.CloseConnection); Comm.Dispose(); //Conn.Close(); //Conn.Dispose(); return(Dr); }
public DataTable ExtcuteDataTable(string ConnString, CommandType CmdType, string CmdText, MySqlParameter[] Parameter, string dbname, bool isTran) { DataSet Ds = new DataSet(); MySqlTransaction transaction; MySqlConnection Conn = new MySqlConnection(ConnString); transaction = Conn.BeginTransaction(); MySqlCommand Comm = new MySqlCommand(); MySqlCmdHeader.CmdParameter(Comm, Conn, null, CmdType, CmdText, Parameter); MySqlDataAdapter Ap = new MySqlDataAdapter(); Ap.SelectCommand = Comm; try { if (!string.IsNullOrEmpty(dbname)) { Ap.Fill(Ds, dbname); } else { Ap.Fill(Ds, "db"); } transaction.Commit();//提交事务 } catch { try { transaction.Rollback();//回滚事务 } catch (Exception ex2) { } } finally { Comm.Dispose(); Conn.Dispose(); Conn.Close(); } if (!string.IsNullOrEmpty(dbname)) { return(Ds.Tables[dbname]); } else { return(Ds.Tables["db"]); } }
/// <summary> /// 执行ExecuteScalar操作,返回第一行第一列 /// </summary> /// <param name="ConnString">数据库连接字符串</param> /// <param name="CmdType">指定如何解释命令字符串</param> /// <param name="CmdText">命令字符串</param> /// <param name="Parameter">参数列表</param> /// <returns></returns> public string ExecuteScalar(string ConnString, CommandType CmdType, string CmdText, MySqlParameter[] Parameter) { string Sin = string.Empty; using (MySqlConnection Conn = new MySqlConnection(ConnString)) { MySqlCommand Comm = new MySqlCommand(); MySqlCmdHeader.CmdParameter(Comm, Conn, null, CmdType, CmdText, Parameter); Sin = Convert.ToString(Comm.ExecuteScalar()); Comm.Dispose(); } return(Sin); }
/// <summary> /// 执行ExecuteNonQuery操作,返回受影响的行数 /// </summary> /// <param name="ConnString">数据库连接字符串</param> /// <param name="CmdType">指定如何解释命令字符串</param> /// <param name="CmdText">命令字符串</param> /// <param name="Parameter">参数列表</param> /// <returns></returns> public int ExecuteNonQuery(string ConnString, CommandType CmdType, string CmdText, MySqlParameter[] Parameter) { int Sin; using (MySqlConnection Conn = new MySqlConnection(ConnString)) { using (MySqlCommand Comm = new MySqlCommand()) { MySqlCmdHeader.CmdParameter(Comm, Conn, null, CmdType, CmdText, Parameter); Sin = Comm.ExecuteNonQuery(); } } return(Sin); }
/// <summary> /// 执行ExecuteReader操作,返回DataTable读取的数据集 /// </summary> /// <param name="ConnString">数据库连接字符串</param> /// <param name="CmdType">指定如何解释命令字符串</param> /// <param name="CmdText">命令字符串</param> /// <param name="Parameter">参数列表</param> /// <returns></returns> public DataTable ExtcuteDataTable(string ConnString, CommandType CmdType, string CmdText, MySqlParameter[] Parameter, string dbname) { DataSet Ds = new DataSet(); MySqlConnection Conn = new MySqlConnection(ConnString); MySqlCommand Comm = new MySqlCommand(); MySqlCmdHeader.CmdParameter(Comm, Conn, null, CmdType, CmdText, Parameter); MySqlDataAdapter Ap = new MySqlDataAdapter(); Ap.SelectCommand = Comm; try { if (!string.IsNullOrEmpty(dbname)) { Ap.Fill(Ds, dbname); } else { Ap.Fill(Ds, "db"); } } catch { } finally { Comm.Dispose(); Conn.Dispose(); Conn.Close(); } if (!string.IsNullOrEmpty(dbname)) { return(Ds.Tables[dbname]); } else { return(Ds.Tables["db"]); } }
public void ExecuteNonQueryNull(string ConnString, CommandType CmdType, string CmdText, MySqlParameter[] Parameter, bool isTran) { MySqlTransaction transaction; using (MySqlConnection Conn = new MySqlConnection(ConnString)) { if (Conn.State != ConnectionState.Open) { Conn.Open(); } transaction = Conn.BeginTransaction(); using (MySqlCommand Comm = new MySqlCommand()) { MySqlCmdHeader.CmdParameter(Comm, Conn, null, CmdType, CmdText, Parameter); Comm.ExecuteNonQuery(); try { Comm.ExecuteNonQuery(); transaction.Commit();//提交事务 } catch (Exception ex) { try { transaction.Rollback();//回滚事务 } catch (Exception ex2) { //Response.Write("回滚错误类型:" + ex2.GetType()); //Response.Write("回滚错误信息:" + ex2.Message); } } Comm.Dispose(); } } }