本文整理汇总了C#中MySql.Data.MySqlClient.MySqlTransaction.Commit方法的典型用法代码示例。如果您正苦于以下问题:C# MySqlTransaction.Commit方法的具体用法?C# MySqlTransaction.Commit怎么用?C# MySqlTransaction.Commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySql.Data.MySqlClient.MySqlTransaction
的用法示例。
在下文中一共展示了MySqlTransaction.Commit方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteCommand
//带参数的执行命令
public static int ExecuteCommand(MySqlTransaction mySqlTransaction,string sql, params MySqlParameter[] values)
{
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
try
{
connection.Open();
mySqlTransaction = connection.BeginTransaction();
MySqlCommand cmd = new MySqlCommand(sql, connection, mySqlTransaction);
cmd.Parameters.AddRange(values);
cmd.ExecuteNonQuery(); // ExecuteNonQuery()一般用于UPDATE、INSERT或DELETE语句,其中唯一的返回值是受影响的记录个数
mySqlTransaction.Commit();
return 1;
}
catch
{
mySqlTransaction.Rollback();
return 0;
}
finally
{
connection.Close();
}
}
}
示例2: save
public bool save(QuestionarioType questionario, int id_empresa)
{
try {
_con.Open();
_transaction = _con.BeginTransaction();
_delete(id_empresa, questionario.idQuestionario);
_insert(questionario);
_transaction.Commit();
}catch(Exception error){
_transaction.Rollback();
_con.Close();
throw error;
}finally{
_con.Close();
}
return true;
}
示例3: CommitTransaction
public void CommitTransaction(MySqlTransaction trans, bool closeConnection)
{
trans.Commit();
if (closeConnection && trans.Connection.State != ConnectionState.Closed)
{
trans.Connection.Close();
}
trans = null;
}
示例4: ExecuteNonQuery
/// <summary>
/// 返回执行响应的行数
/// </summary>
/// <param name="trans">command中执行的事物(MySqlTransaction)</param>
/// <param name="cmdType">执行类型(过程/语句)</param>
/// <param name="cmdText">执行的过程名称/查询语句</param>
/// <param name="commandParameters">command执行的MySqlParameter[]数组</param>
/// <returns>int 返回command执行响应的行数</returns>
public static int ExecuteNonQuery(MySqlTransaction trans, CommandType cmdType, string cmdText, params MySqlParameter[] commandParameters)
{
int val = 0;
MySqlCommand cmd = new MySqlCommand();
try
{
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, commandParameters);
val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
//Close(trans.Connection);
//Dispose(trans.Connection);
trans.Commit();
return val;
}
catch
{
trans.Rollback();
return val;
}
}
示例5: TransaccionMysql
public Boolean TransaccionMysql(String query, MySqlParameterCollection parametros, System.Data.CommandType tipo_comando)
{
Boolean respuesta = false;
int f;
try{
transaccion = canal.BeginTransaction();
MySqlCommand comando = new MySqlCommand(query, canal);
comando.CommandType = tipo_comando;
if (parametros != null) {
foreach (var item in parametros){
comando.Parameters.Add(item);
}
}
comando.Transaction = transaccion;
f= comando.ExecuteNonQuery();
transaccion.Commit();
if (f>=0){
respuesta = true;
}
else{
respuesta = false;
}
}catch (Exception ex){
transaccion.Rollback();
MessageBox.Show("error sql:" + ex.Message);
respuesta = false;
}
return respuesta;
}
示例6: enviarButton_Click
//.........这里部分代码省略.........
{
if (!column.ColumnName.Equals("id"))
{
insert = insert + column.ColumnName + ",";
}
}
insert = insert + "nome_lote,";
insert = insert.Remove(insert.Length - 1, 1);
insert = insert + ") VALUES (";
foreach (DataColumn column in citeluzDataSet.material.Columns)
{
object valor = rowMaterial[column.ColumnName];
if (column.ColumnName.Equals("id"))
{
codMaterial = (int)valor;
}
if (column.DataType == typeof(string))
{
valor = Library.removeCrase(valor.ToString());
valor = "'" + valor + "'";
}
else
{
if (valor.ToString().Length == 0)
{
valor = "null";
}
}
if (!column.ColumnName.Equals("id"))
{
insert = insert + valor + ",";
}
}
insert = insert + "'" + txtNomeLote.Text.Trim().ToUpper() + "',";
insert = insert.Remove(insert.Length - 1, 1);
insert = insert + ");";
try
{
mycommand.CommandText = insert;
mycommand.ExecuteNonQuery();
listBox1.Items.Add("Material " + codMaterial + " enviada");
listBox1.SelectedIndex = listBox1.Items.Count - 1;
Application.DoEvents();
}
catch (Exception ex)
{
mytrans.Rollback();
myconn.Close();
MessageBox.Show(ex.Message);
listBox1.Items.Add(ex.Message);
listBox1.SelectedIndex = listBox1.Items.Count - 1;
trafoTableAdapter.Fill(citeluzDataSet.trafo);
Cursor.Current = Cursors.Default;
Application.DoEvents();
return;
}
}
}
catch (Exception ex)
{
mytrans.Rollback();
myconn.Close();
MessageBox.Show(ex.Message);
listBox1.Items.Add(ex.Message);
listBox1.SelectedIndex = listBox1.Items.Count - 1;
trafoTableAdapter.Fill(citeluzDataSet.trafo);
Cursor.Current = Cursors.Default;
Application.DoEvents();
return;
}
}
}
catch (Exception ex)
{
mytrans.Rollback();
myconn.Close();
MessageBox.Show(ex.Message);
listBox1.Items.Add(ex.Message);
listBox1.SelectedIndex = listBox1.Items.Count - 1;
trafoTableAdapter.Fill(citeluzDataSet.trafo);
Cursor.Current = Cursors.Default;
Application.DoEvents();
return;
}
}
mytrans.Commit();
myconn.Close();
listBox1.Items.Add("Envio completo.");
listBox1.SelectedIndex = listBox1.Items.Count - 1;
Cursor.Current = Cursors.Default;
Application.DoEvents();
}
示例7: CloseConnectionAndEndTransaction
public static void CloseConnectionAndEndTransaction(MySqlConnection connection, MySqlTransaction transaction)
{
if (transaction != null) transaction.Commit();
CloseConnection(connection);
}
示例8: enviarDados_click
//.........这里部分代码省略.........
DataRowView row =
(DataRowView)projetoBindingSource.Current;
projetoTableAdapter.FillById(lptDataSet.projeto, (int)row["id"]);
}
Cursor.Current = Cursors.WaitCursor;
Application.DoEvents();
mycommand = myconn.CreateCommand();
mytrans = myconn.BeginTransaction();
mycommand.Connection = myconn;
mycommand.Transaction = mytrans;
foreach (DataRow row in lptDataSet.projeto.Rows)
{
insert = "INSERT INTO projeto (";
foreach (DataColumn column in lptDataSet.projeto.Columns)
{
if (!column.ColumnName.Equals("id"))
{
insert = insert + column.ColumnName + ",";
}
}
insert = insert.Remove(insert.Length - 1, 1);
insert = insert + ") VALUES (";
foreach (DataColumn column in lptDataSet.projeto.Columns)
{
if (column.ColumnName.Equals("id"))
{
idLocal = Convert.ToInt32(row[column.ColumnName]);
}
else
{
object valor = row[column.ColumnName];
if (column.DataType == typeof(string))
{
valor = Library.removeCrase(valor.ToString());
valor = "'" + valor + "'";
}
else
{
if (valor.ToString().Length == 0)
{
valor = "null";
}
}
insert = insert + valor + ",";
}
}
insert = insert.Remove(insert.Length - 1, 1);
insert = insert + ");";
//insere
try
{
mycommand.CommandText = insert;
mycommand.ExecuteNonQuery();
listBox1.Items.Add("Projeto " + idLocal + " enviado");
listBox1.SelectedIndex = listBox1.Items.Count - 1;
Application.DoEvents();
mycommand =
new MySqlCommand("SELECT @@IDENTITY", myconn);
object id_ = mycommand.ExecuteScalar();
idMysql = Convert.ToInt32(id_);
insert = "";
insereClientesByProjetoId(idLocal, idMysql);
insereFaixaByProjetoId(idLocal, idMysql);
insereSangriaByProjetoId(idLocal, idMysql);
insereSignificativoByProjetoId(idLocal, idMysql);
insereMedidorByProjetoId(idLocal, idMysql);
}
catch (Exception ex)
{
mytrans.Rollback();
MessageBox.Show(ex.Message);
listBox1.Items.Add(ex.Message);
listBox1.SelectedIndex = listBox1.Items.Count - 1;
projetoTableAdapter.Fill(lptDataSet.projeto);
Cursor.Current = Cursors.Default;
Application.DoEvents();
return;
}
}
mytrans.Commit();
MessageBox.Show("Dados enviados");
projetoTableAdapter.Fill(lptDataSet.projeto);
myconn.Close();
Cursor.Current = Cursors.Default;
Application.DoEvents();
}
示例9: DoTransaction
/// <summary>
/// Do this in a transaction, and handle all transaction and connection issues that might occur
/// </summary>
/// <param name="act">What to do...</param>
/// <param name="isolationLevel">The isolation level to use</param>
private void DoTransaction(Action act, IsolationLevel isolationLevel = IsolationLevel.Serializable)
{
MySqlConnection conn = Connection;
try
{
RetryUtility.RetryAction(() =>
{
try
{
_transaction = conn.BeginTransaction(isolationLevel);
act();
_transaction.Commit();
}
catch (Exception)
{
try
{
_transaction.Rollback();
}
catch (Exception)
{
_connection = null;
//If we can't rollback, clear the connection; something is very wrong...
//SKIPPEDTODO: Make a logging function and maybe a security alert...
}
throw;
}
}, 3, 700);
}
catch (Exception ex)
{
throw new Exception("Something unexpected went wrong. The error has been logged. Please try again.", ex);
}
_transaction = null;
}
示例10: updateUser
public void updateUser(string pUserId, string pPassword, string pRole, string pSection)
{
try
{
loMySqlTransaction = GlobalVariables.goMySqlConnection.BeginTransaction();
loUser = new User();
loUser.userID = pUserId;
loUser.password = pPassword;
loUser.defaultSection = pSection;
loUser.update(ref loMySqlTransaction);
loUserRole = new UserRole();
loUserRole.RoleName = pRole;
loUserRole.UserId = pUserId;
loUserRole.insert(ref loMySqlTransaction);
loMySqlTransaction.Commit();
}
catch (Exception)
{
loMySqlTransaction.Rollback();
throw;
}
}
示例11: uploadFiles
//.........这里部分代码省略.........
//para ni sa loading text -- first 100 words
_progressCount[1] = 6;
FileUpload.GetType().GetMethod("reportProgress").Invoke(FileUpload, _progressCount);
//^para sa loading text
//get the document contents, but check for it's doctype first though!
switch (loDocument.Doctype)
{
case ".rtf":
case ".doc":
string _docContents = "";
_oApplication = new Microsoft.Office.Interop.Word.Application();
_oDocument = _oApplication.Documents.Open(poGrid.GetDataDisplay(i, "Local Path"));
//loop throught the first 100 words
int _numberOfWords = 0;
if (_oDocument.Words.Count >= 100)
{
_numberOfWords = 100;
}
else
{
_numberOfWords = _oDocument.Words.Count;
}
for (int _wordCount = 1; _wordCount <= _numberOfWords; _wordCount++)
{
_docContents += _oDocument.Words[_wordCount].Text;
}
string[] _docContentsArr = _docContents.Split(_whiteSpaceSeparator, StringSplitOptions.RemoveEmptyEntries);
IList<string> _docContentsList = GlobalFunctions.removeRedundancy(_docContentsArr);
foreach (string _str in _docContentsList)
{
if (_str.Length > 1)
{
loDocTag.Tag = _str.ToLower().Trim();
loDocTag.DocumentId = _docId;
try
{
loDocTag.insert(ref loMySqlTransaction);
}
catch { }
}
}
break;
case ".txt":
string _textContents = File.ReadAllText(poGrid.GetDataDisplay(i, "Local Path"));
string[] _textContentsArr = _textContents.Split(_whiteSpaceSeparator, StringSplitOptions.RemoveEmptyEntries);
IList<string> _textContentsList = GlobalFunctions.removeRedundancy(_textContentsArr);
foreach (string _str in _textContentsList)
{
if (_str.Length > 1)
{
loDocTag.Tag = _str.ToLower().Trim();
loDocTag.DocumentId = _docId;
try
{
loDocTag.insert(ref loMySqlTransaction);
}
catch { }
}
}
break;
}
//maypa ang mysqltransaction, mu commit!
loMySqlTransaction.Commit();
//copy file to server
File.Copy(@"" + poGrid.GetDataDisplay(i, "Local Path"), @"" + GlobalVariables.goFileServer + @"\" + _docId + loDocument.Doctype);
//para ni sa loading text -- first 100 words
_progressCount[1] = 7;
FileUpload.GetType().GetMethod("reportProgress").Invoke(FileUpload, _progressCount);
//^para sa loading text
}
catch (Exception)
{
loMySqlTransaction.Rollback();
throw;
}
finally
{
if (_oDocument != null)
{
_oDocument.Close();
_oApplication.Quit();
}
GC.Collect();
}
}
}
示例12: uploadImages
//.........这里部分代码省略.........
catch { }
}
//para ni sa loading text -- saving hidden tags to db
_progressCount[1] = 3;
ImageUpload.GetType().GetMethod("reportProgress").Invoke(ImageUpload, _progressCount);
//^para sa loading text
IList<string> _hiddenTagList = new List<string>();
//start with the dates
DateTime _dateTaken = DateTime.Parse(poGrid.GetDataDisplay(i, "Date Taken"));
_hiddenTagList.Add(_dateTaken.ToString("yyyy")); //year
_hiddenTagList.Add(_dateTaken.ToString("MMM")); //short month name
_hiddenTagList.Add(_dateTaken.ToString("MMMM")); //month name
_hiddenTagList.Add(_dateTaken.ToShortDateString());
_hiddenTagList.Add(_dateTaken.ToLongDateString());
_hiddenTagList.Add(_dateTaken.ToString("yyyy-MM-dd"));
_hiddenTagList.Add(_dateTaken.ToString("dd-MM-yy"));
//title
string[] _titleArr = loImage.Title.Split(_whiteSpaceSeparator, StringSplitOptions.RemoveEmptyEntries);
IList<string> _titleList = GlobalFunctions.removeRedundancy(_titleArr);
foreach (string _str in _titleList)
{
_hiddenTagList.Add(_str);
}
//photographer
string[] _photographerArr = poGrid.GetDataDisplay(i, "Photographer").Split(_whiteSpaceSeparator, StringSplitOptions.RemoveEmptyEntries);
IList<string> _photographerList = GlobalFunctions.removeRedundancy(_photographerArr);
foreach (string _str in _photographerList)
{
_hiddenTagList.Add(_str);
}
//caption
string[] _captionArr = loImage.Caption.Split(_whiteSpaceSeparator, StringSplitOptions.RemoveEmptyEntries);
IList<string> _captionList = GlobalFunctions.removeRedundancy(_captionArr);
foreach (string _str in _captionList)
{
_hiddenTagList.Add(_str);
}
//location
string[] _locationArr = loImage.Location.Split(_whiteSpaceSeparator, StringSplitOptions.RemoveEmptyEntries);
IList<string> _locationList = GlobalFunctions.removeRedundancy(_locationArr);
foreach (string _str in _captionList)
{
_hiddenTagList.Add(_str);
}
//remove repetitive entries
IList<string> _noRepeatHiddenTags = GlobalFunctions.removeRedundancy(_hiddenTagList.ToArray<string>());
//save to database like a baws
foreach (string _str in _noRepeatHiddenTags)
{
if (_str != "" || _str != null)
{
loImageTag.Tag = _str.ToLower().Trim();
loImageTag.ImageId = _imageId;
try
{
loImageTag.insert(ref loMySqlTransaction);
}
catch { }
}
}
loMySqlTransaction.Commit();
//File.Copy(@"" + poGrid.GetDataDisplay(i, "Local Path"), @"" + GlobalVariables.goImageServer + @"\" + _imageId + loImage.Type);
//para ni sa loading text -- copying image to server
_progressCount[1] = 4;
ImageUpload.GetType().GetMethod("reportProgress").Invoke(ImageUpload, _progressCount);
//^para sa loading text
Stream buffer;
StreamReader srImage = new StreamReader(poGrid.GetDataDisplay(i, "Local Path"));
buffer = srImage.BaseStream;
Bitmap bmImage = new Bitmap(buffer);
bmImage.Save(GlobalVariables.goImageServer + @"\" + _imageId + loImage.Type);
//para ni sa loading text -- done
_progressCount[1] = 5;
ImageUpload.GetType().GetMethod("reportProgress").Invoke(ImageUpload, _progressCount);
//^para sa loading text
}
catch (Exception ex)
{
loMySqlTransaction.Rollback();
throw;
}
}
}