本文整理汇总了C#中MySql.Data.MySqlClient.MySqlConnection.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# MySqlConnection.Dispose方法的具体用法?C# MySqlConnection.Dispose怎么用?C# MySqlConnection.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySql.Data.MySqlClient.MySqlConnection
的用法示例。
在下文中一共展示了MySqlConnection.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
/// <summary>
/// 修改数据
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public int Update(Policy entity)
{
string sql = "UPDATE tb_policy SET [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],";
sql = sql + " [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected] where [email protected] ";
//string sql = "UPDATE cimuser SET [email protected] WHERE [email protected]";
using (MySqlConnection mycn = new MySqlConnection(mysqlConnection))
{
mycn.Open();
MySqlCommand command = new MySqlCommand(sql, mycn);
command.Parameters.AddWithValue("@agentType", entity.agentType);
command.Parameters.AddWithValue("@sequence", entity.sequence);
command.Parameters.AddWithValue("@subject", entity.subject);
command.Parameters.AddWithValue("@content", entity.content);
command.Parameters.AddWithValue("@sender", entity.sender);
command.Parameters.AddWithValue("@attachment", entity.attachment);
command.Parameters.AddWithValue("@attachmentName", entity.attachmentName);
command.Parameters.AddWithValue("@creatTime", entity.creatTime);
command.Parameters.AddWithValue("@type", entity.type);
command.Parameters.AddWithValue("@validateStartTime", entity.validateStartTime);
command.Parameters.AddWithValue("@validateEndTime", entity.validateEndTime);
command.Parameters.AddWithValue("@isValidate", entity.isValidate);
command.Parameters.AddWithValue("@isDelete", entity.isDelete);
command.Parameters.AddWithValue("@deleteTime", entity.deleteTime);
command.Parameters.AddWithValue("@toAll", entity.toAll);
int i = command.ExecuteNonQuery();
mycn.Close();
mycn.Dispose();
return i;
}
}
示例2: GeneralNonSelectQuery
/// <summary>
/// 一个公用interface执行所有非 select语句
/// </summary>
/// <param name="non_query_type"></param>
/// <returns>返回影响数据库几行</returns>
public int GeneralNonSelectQuery(MySqlCommand cmd)
{
int iReturn = 0;
string connStr = sql.GetSQL(sql.SQL.S_CONNECTION_STR);
MySqlConnection conn = new MySqlConnection(connStr);
try
{
conn.Open();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
iReturn = cmd.ExecuteNonQuery();
cmd.Dispose();
conn.Close();
conn.Dispose();
}
catch (Exception ex)
{
cmd.Dispose();
conn.Close();
conn.Dispose();
}
return iReturn;
}
示例3: ConnectionTest
public string ConnectionTest()
{
s = ConfigurationManager.AppSettings["MySql"].ToString();
MySqlConnection mysqlcon = new MySqlConnection(s);
MySqlCommand mysqlcom = new MySqlCommand("", mysqlcon);
MySqlDataAdapter mysqldataadp = new MySqlDataAdapter(mysqlcom);
DataSet ds=new DataSet();
string message = "";
try
{
//mysqlcon.Open();
if (mysqlcon.State != ConnectionState.Open)
{
mysqlcon.Open();
}
mysqldataadp.SelectCommand.CommandText="select * from ow_articletype";
message = "打开数据库成功!";
mysqldataadp.Fill(ds);
if (ds.Tables.Count > 0)
{
message = ds.Tables[0].Rows[0][1].ToString();
}
else
{
message = "可惜查不到数据";
}
}
catch (Exception ex)
{
if(mysqlcon.State==ConnectionState.Open)
{
mysqlcon.Close();
mysqlcon.Dispose();
}
message = "数据库访问失败! 信息:"+ex.Message;
}
finally
{
if (mysqlcon.State == ConnectionState.Open)
{
mysqlcon.Close();
}
mysqlcon.Dispose();
mysqlcom.Dispose();
mysqldataadp.Dispose();
}
return message;
}
示例4: ContactsDropDownList_SelectedIndexChanged
protected void ContactsDropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
ProjectsDropDownList.Items.Clear();
ProjectsDropDownList.Items.Add(new ListItem("--Select Project--", ""));
ProjectsDropDownList.AppendDataBoundItems = true;
DBConnection = new MySqlConnection(objUKFilmLocation.DBConnect);
DBCommand = DBConnection.CreateCommand();
DBConnection.Open();
DBCommand.CommandText = "select ProjectID, WorkingTitle from ProjectDetails where ContactID = '" + ProjectContactsDropDownList.SelectedItem.Value + "' order by WorkingTitle Asc;";
ProjectsDropDownList.DataSource = DBCommand.ExecuteReader();
ProjectsDropDownList.DataTextField = "WorkingTitle";
ProjectsDropDownList.DataValueField = "ProjectID";
ProjectsDropDownList.DataBind();
if (ProjectsDropDownList.Items.Count > 1)
{
ProjectsDropDownList.Enabled = true;
}
ProjectsDropDownList.Visible = true;
DBConnection.Close();
DBConnection.Dispose();
}
示例5: lista_Documentos
public DataTable lista_Documentos()
{
DataTable dtDocumentos = new DataTable();
MySqlConnection oSC = new MySqlConnection();
try
{
cls_Conexion oConexion = new cls_Conexion();
oSC = oConexion.conexion();
oSC.Open();
MySqlDataAdapter daDoc = new MySqlDataAdapter("SELECT * FROM tbl_TipoDocumento", oSC);
daDoc.Fill(dtDocumentos);
return dtDocumentos;
}
catch(Exception e)
{
string strError = e.Message;
throw new Exception(strError);
throw new Exception("Error al Recuperar Datos Verifique");
}
finally
{
oSC.Close();
oSC.Dispose();
}
return null;
}
示例6: GetDBConnection
public MySqlConnection GetDBConnection()
{
try
{
MySqlConnection db;
if (_databaseQueue.Count > 0)
{
db = _databaseQueue.Dequeue();
System.Threading.ThreadPool.QueueUserWorkItem(ProcessDatabaseQueue);
}
else
{
db = new MySqlConnection(Config.GetConnectionString());
db.Open();
}
return db;
}
catch (MySqlException e)
{
MySqlConnection db = new MySqlConnection();
Logger.WriteLog(e.Message, Logger.LogType.Error);
db.Dispose();
return db;
}
}
示例7: Add
public const string mysqlConnection = DBConstant.mysqlConnection;//"User Id=root;Host=115.29.229.134;Database=chinaunion;password=c513324665;charset=utf8";
/// <summary>
/// 添加数据
/// </summary>
/// <returns></returns>
public int Add(ExamQuestion entity)
{
string sql = "INSERT INTO tb_exam_question (exam_sequence,questionType,answer,question,option1,option2,option3,option4,option5,option6,option7,option8)";
sql = sql + " VALUE (@exam_sequence,@questionType,@answer,@question,@option1,@option2,@option3,@option4,@option5,@option6,@option7,@option8)";
using (MySqlConnection mycn = new MySqlConnection(mysqlConnection))
{
mycn.Open();
MySqlCommand command = new MySqlCommand(sql, mycn);
command.Parameters.AddWithValue("@exam_sequence", entity.exam_sequence);
command.Parameters.AddWithValue("@questionType", entity.questionType);
command.Parameters.AddWithValue("@answer", entity.answer);
command.Parameters.AddWithValue("@question", entity.question);
command.Parameters.AddWithValue("@option1", entity.option1);
command.Parameters.AddWithValue("@option2", entity.option2);
command.Parameters.AddWithValue("@option3", entity.option3);
command.Parameters.AddWithValue("@option4", entity.option4);
command.Parameters.AddWithValue("@option5", entity.option5);
command.Parameters.AddWithValue("@option6", entity.option6);
command.Parameters.AddWithValue("@option7", entity.option7);
command.Parameters.AddWithValue("@option8", entity.option8);
int i = command.ExecuteNonQuery();
mycn.Close();
mycn.Dispose();
return i;
}
}
示例8: Update
/// <summary>
/// 修改数据
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public int Update(InvoicePayment entity)
{
string sql = "UPDATE tb_invoice_payment SET [email protected],[email protected],[email protected],";
sql = sql + "[email protected],[email protected],[email protected],[email protected]";
sql = sql + "[email protected],[email protected],[email protected]";
sql = sql + " where [email protected] and [email protected] and [email protected]";
//string sql = "UPDATE cimuser SET [email protected] WHERE [email protected]";
using (MySqlConnection mycn = new MySqlConnection(mysqlConnection))
{
mycn.Open();
MySqlCommand command = new MySqlCommand(sql, mycn);
command.Parameters.AddWithValue("@agentNo", entity.agentNo);
command.Parameters.AddWithValue("@agentName", entity.agentName);
command.Parameters.AddWithValue("@month", entity.month);
command.Parameters.AddWithValue("@receivedTime", entity.receivedTime);
command.Parameters.AddWithValue("@processTime", entity.processTime);
command.Parameters.AddWithValue("@content", entity.content);
command.Parameters.AddWithValue("@invoiceFee", entity.invoiceFee);
command.Parameters.AddWithValue("@invoiceType", entity.invoiceType);
command.Parameters.AddWithValue("@invoiceNo", entity.invoiceNo);
command.Parameters.AddWithValue("@payStatus", entity.payStatus);
int i = command.ExecuteNonQuery();
mycn.Close();
mycn.Dispose();
return i;
}
}
示例9: conn
public ActionResult conn()
{
MySqlConnection con = new MySqlConnection("server=us-cdbr-iron-east-02.cleardb.net;database=ad_55b0f9c367ab0d1;uid=ba331630319965;pwd=603b8557");
MySqlDataReader dr;
try
{
con.Open();
//MySqlCommand cmd = new MySqlCommand("create table Service_Application(service_id int, firstname varchar(50),middlename varchar(50),lastname varchar(50) )", con);
MySqlCommand cmd = new MySqlCommand("select * from Service_Application", con);
//cmd.ExecuteNonQuery();
dr = cmd.ExecuteReader();
string result = string.Empty;
while (dr.Read())
{
for (int i = 0; i < dr.FieldCount; i++)
result+= dr.GetValue(i).ToString() + ", ";
}
TempData["name"] = result;
return View("~/Views/Shared/View.cshtml");
}
finally
{
con.Dispose();
}
}
示例10: Update
/// <summary>
/// 修改数据
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public int Update(AgentComplain entity)
{
string sql = "UPDATE tb_complain SET [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],";
sql = sql + " [email protected],[email protected],[email protected] where [email protected] ";
//string sql = "UPDATE cimuser SET [email protected] WHERE [email protected]";
using (MySqlConnection mycn = new MySqlConnection(mysqlConnection))
{
mycn.Open();
MySqlCommand command = new MySqlCommand(sql, mycn);
command.Parameters.AddWithValue("@agentNo", entity.agentNo);
command.Parameters.AddWithValue("@userName", entity.userName);
command.Parameters.AddWithValue("@sequence", entity.sequence);
command.Parameters.AddWithValue("@processCode", entity.processCode);
command.Parameters.AddWithValue("@joinTime", entity.joinTime);
command.Parameters.AddWithValue("@joinMenu", entity.joinMenu);
command.Parameters.AddWithValue("@content", entity.content);
command.Parameters.AddWithValue("@processBranchCode", entity.processBranchCode);
command.Parameters.AddWithValue("@processBranchName", entity.processBranchName);
command.Parameters.AddWithValue("@replyTime", entity.replyTime);
command.Parameters.AddWithValue("@comment", entity.comment);
command.Parameters.AddWithValue("@createTime", entity.createTime);
int i = command.ExecuteNonQuery();
mycn.Close();
mycn.Dispose();
return i;
}
}
示例11: Add
public const string mysqlConnection = DBConstant.mysqlConnection;//"User Id=root;Host=115.29.229.134;Database=chinaunion;password=c513324665;charset=utf8";
/// <summary>
/// 添加数据
/// </summary>
/// <returns></returns>
public int Add(InvoicePayment entity)
{
string sql = "INSERT INTO tb_invoice_payment (agentNo,agentName,month,receivedTime,processTime,content,invoiceFee,invoiceType,invoiceNo,payStatus) VALUE (@agentNo,@agentName,@month,@receivedTime,@processTime,@content,@invoiceFee,@invoiceType,@invoiceNo,@payStatus)";
using (MySqlConnection mycn = new MySqlConnection(mysqlConnection))
{
mycn.Open();
MySqlCommand command = new MySqlCommand(sql, mycn);
command.Parameters.AddWithValue("@agentNo", entity.agentNo);
command.Parameters.AddWithValue("@agentName", entity.agentName);
command.Parameters.AddWithValue("@month", entity.month);
command.Parameters.AddWithValue("@receivedTime", entity.receivedTime);
command.Parameters.AddWithValue("@processTime", entity.processTime);
command.Parameters.AddWithValue("@content", entity.content);
command.Parameters.AddWithValue("@invoiceFee", entity.invoiceFee);
command.Parameters.AddWithValue("@invoiceType", entity.invoiceType);
command.Parameters.AddWithValue("@invoiceNo", entity.invoiceNo);
command.Parameters.AddWithValue("@payStatus", entity.payStatus);
int i = command.ExecuteNonQuery();
mycn.Close();
mycn.Dispose();
return i;
}
}
示例12: _Adicionar
public bool _Adicionar(Lojas _loja, string stringConnect)
{
try
{
MySqlConnection conexao = new MySqlConnection(stringConnect);
var sql = new MySqlCommand("INSERT INTO `Loja` (`L_Loja` , `L_Responsavel` , `L_Telefone` , `L_Email` ) VALUES (@L_Loja, @L_Responsavel, @L_Telefone, @L_Email);", conexao);
sql.Parameters.AddWithValue("@L_Loja", _loja.l_loja);
sql.Parameters.AddWithValue("@L_Responsavel", _loja.l_responsavel);
sql.Parameters.AddWithValue("@L_Telefone", _loja.l_telefone);
sql.Parameters.AddWithValue("@L_Email", _loja.l_email);
conexao.Open();
sql.ExecuteScalar();
if (conexao.State == ConnectionState.Open)
{
conexao.Close();
conexao.Dispose();
}
sql.Dispose();
return true;
}
catch (Exception)
{
return false;
}
}
示例13: Update
/// <summary>
/// 修改数据
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public int Update(AgentInvoice entity)
{
string sql = "UPDATE agent_invoice SET [email protected],[email protected],[email protected],";
sql = sql + "[email protected],[email protected],[email protected],[email protected],";
sql = sql + "[email protected] ,[email protected] where [email protected] and [email protected] and [email protected]";
//string sql = "UPDATE cimuser SET [email protected] WHERE [email protected]";
using (MySqlConnection mycn = new MySqlConnection(mysqlConnection))
{
mycn.Open();
MySqlCommand command = new MySqlCommand(sql, mycn);
command.Parameters.AddWithValue("@agentNo", entity.agentNo);
command.Parameters.AddWithValue("@agentName", entity.agentName);
command.Parameters.AddWithValue("@invoiceMonth", entity.invoiceMonth);
command.Parameters.AddWithValue("@invoiceNo", entity.invoiceNo);
command.Parameters.AddWithValue("@invoiceDate", entity.invoiceDate);
command.Parameters.AddWithValue("@invoiceContent", entity.invoiceContent);
command.Parameters.AddWithValue("@invoiceType", entity.invoiceType);
command.Parameters.AddWithValue("@invoiceFee", entity.invoiceFee);
command.Parameters.AddWithValue("@comment", entity.comment);
int i = command.ExecuteNonQuery();
mycn.Close();
mycn.Dispose();
return i;
}
}
示例14: Add
public const string mysqlConnection = DBConstant.mysqlConnection;//"User Id=root;Host=115.29.229.134;Database=chinaunion;password=c513324665;charset=utf8";
/// <summary>
/// 添加数据
/// </summary>
/// <returns></returns>
public int Add(AgentContact entity)
{
string sql = "INSERT INTO agent_Contact (agentNo,agentName,branchNo,branchName,area,zone,contactTel,contactName,contactEmail) VALUE (@agentNo,@agentName,@branchNo,@branchName,@area,@zone,@contactTel,@contactName,@contactEmail)";
using (MySqlConnection mycn = new MySqlConnection(mysqlConnection))
{
mycn.Open();
MySqlCommand command = new MySqlCommand(sql, mycn);
command.Parameters.AddWithValue("@agentNo", entity.agentNo);
command.Parameters.AddWithValue("@agentName", entity.agentName);
command.Parameters.AddWithValue("@branchNo", entity.branchNo);
command.Parameters.AddWithValue("@branchName", entity.branchName);
command.Parameters.AddWithValue("@area", entity.area);
command.Parameters.AddWithValue("@zone", entity.zone);
command.Parameters.AddWithValue("@contactTel", entity.contactTel);
command.Parameters.AddWithValue("@contactName", entity.contactName);
command.Parameters.AddWithValue("@contactEmail", entity.contactEmail);
int i = command.ExecuteNonQuery();
mycn.Close();
mycn.Dispose();
return i;
}
}
示例15: SqlLogin
public static void SqlLogin()
{
MySqlConnection conn = null;
conn = new MySqlConnection("Host = localhost;Database = test;Username = root;Password = kaokao");
string sql = "select * from user where username='" + NeededValue.Username + "' and password='" +
NeededValue.Password + "' and hwid='" + NeededValue.Hwid + "'";
conn.Open();
MySqlCommand comm = new MySqlCommand(sql, conn);
MySqlDataReader reader = comm.ExecuteReader();
try
{
if (reader.Read())
{
NeededValue.Loginflag = 1;
}
else
{
NeededValue.Loginflag = 0;
}
}
catch (Exception error)
{
MessageBox.Show(text: error.Message);
}
finally
{
conn.Close();
conn.Dispose();
reader .Dispose();
}
}