本文整理汇总了C#中MySql.Data.MySqlClient.MySqlConnection.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# MySqlConnection.Clone方法的具体用法?C# MySqlConnection.Clone怎么用?C# MySqlConnection.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySql.Data.MySqlClient.MySqlConnection
的用法示例。
在下文中一共展示了MySqlConnection.Clone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ViewDB
public void ViewDB()
{
String database = "class" + classSec + "_db";
String connectionStr = "Server=localhost; Port=3306; Database=" + database +"; Uid=root; Pwd=admin;";
MySqlConnection connection = new MySqlConnection(connectionStr);
connection.Open();
try
{
MySqlCommand cmd = connection.CreateCommand();
cmd.CommandText = "SELECT * FROM studentinfo";
MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);
dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
catch(Exception)
{
throw;
}
finally
{
if(connection.State == ConnectionState.Open)
{
connection.Clone();
}
}
}
示例2: db_connect
public void db_connect ()
{
string server = "10.3.30.82";
string user = "user01";
string password = "";
string database = "jscom";
MySqlConnection conn = new MySqlConnection();
conn.ConnectionString = "server=" + server + ";Uid=" + user + ";Pwd=" + password + ";database=" + database;
try
{
conn.Open();
}
catch (Exception)
{
MessageBox.Show("x");
}
finally
{
conn.Clone();
}
}
示例3: button2_Click
private void button2_Click(object sender, EventArgs e)
{
string MyConnectionString = "Server=serwer1585870.home.pl;Database=18659907_0000002;Uid=18659907_0000002;Pwd=#bazalukasza;";
MySqlConnection connection = new MySqlConnection(MyConnectionString);
connection.Open();
try
{
MySqlCommand cmd = connection.CreateCommand();
cmd.CommandText = "select * FROM tb_movies";
MySqlDataAdapter adap = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
adap.Fill(ds);
dataGridView2.DataSource = ds.Tables[0].DefaultView;
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (connection.State == ConnectionState.Open)
{
connection.Clone();
}
}
}
示例4: Save
public void Save()
{
MySqlConnection conn = new MySqlConnection(Globals.ConnectionString);
MySqlCommand cmd = new MySqlCommand("insert into tasktypes (tt_name) values (@name)", conn);
cmd.Parameters.Add( new MySqlParameter("name", MySqlDbType.VarChar)).Value = this.Name;
conn.Open();
cmd.ExecuteNonQuery();
conn.Clone();
}
示例5: Delete
public void Delete()
{
MySqlConnection conn = new MySqlConnection(Globals.ConnectionString);
MySqlCommand cmd = new MySqlCommand("delete from groups where g_id = @id", conn);
cmd.Parameters.Add( new MySqlParameter("id", MySqlDbType.Int32)).Value = this.Id;
conn.Open();
cmd.ExecuteNonQuery();
conn.Clone();
}
示例6: Main
public static void Main(string[] args)
{
MySqlConnection mySqlConnection = new MySqlConnection (
"Database=dbprueba;Data Source=localhost;User Id=root;Password=root"
);
mySqlConnection.Open ();
MySqlCommand mySqlCommand = mySqlConnection.CreateCommand ();
mySqlCommand.CommandText = "SELECT * FROM articulo";
MySqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader ();
showColumnNames (mySqlDataReader);
showRows (mySqlDataReader);
mySqlDataReader.Close ();
mySqlConnection.Clone ();
}
示例7: executeQuery
public override void executeQuery(string queryString)
{
try {
using (var conn = new MySqlConnection(connString))
{
conn.Open();
if (queryString.IndexOf("CREATE DATABASE") != -1)
conn.ChangeDatabase(ServerSettings.GetSetting("MySQL-DBName"));
MySqlCommand cmd = new MySqlCommand(queryString, conn);
cmd.ExecuteNonQuery();
conn.Clone();
conn.Dispose();
}
}
catch (Exception e)
{
Server.Log(e);
}
}
示例8: Cadastro
public void Cadastro(Modelo mo)
{
string caminho = "SERVER=localhost;DATABASE=dbexemplo;UID=root;PASS=";
try
{
conexao = new MySqlConnection(caminho);
conexao.Open();
string inserir = String.Format
("INSERT INTO tbexemplo(nome, email) VALUES('{0}', '{1}');", mo.Nome, mo.Email);
MySqlCommand comandos = new MySqlCommand(inserir, conexao);
comandos.ExecuteNonQuery();
conexao.Clone();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
示例9: Initialize
/// <summary>
/// Initialize connection to DB
/// </summary>
/// <param name="host">Host</param>
/// <param name="database">Database</param>
/// <param name="user">User</param>
/// <param name="password">Password</param>
/// <returns>Return true if connection success</returns>
public static bool Initialize(string host, string database, string user, string password)
{
if (_connection != null && _connection.State == ConnectionState.Open)
{
CloseConnection();
}
var connectionString = "SERVER=" + host + ";UID=" + user + ";PASSWORD=" + password;
_connection = new MySqlConnection(connectionString);
if (OpenConnection())
{
CreateDataBase(database);
if (_connection.State == ConnectionState.Open)
_connection.Clone();
}
else
return false;
var connectionDbString = "SERVER=" + host + ";DATABASE=" + database + ";UID=" + user + ";PASSWORD=" + password;
_connection = new MySqlConnection(connectionDbString);
if (OpenConnection())
{
CreateTables();
return true;
}
return false;
}
示例10: Update
public void Update()
{
MySqlConnection conn = new MySqlConnection(Globals.ConnectionString);
MySqlCommand cmd = new MySqlCommand("update schedule set " +
"t_id = @t_id, " +
"t_start = @t_start, " +
"t_finish = @t_finish, " +
"r_id = @r_id " +
"where s_id = @s_id", conn);
cmd.Parameters.Add( new MySqlParameter("s_id", MySqlDbType.Int32)).Value = this.ScheduleId;
cmd.Parameters.Add( new MySqlParameter("t_id", MySqlDbType.Int32)).Value = this.TaskId;
cmd.Parameters.Add( new MySqlParameter("t_start", MySqlDbType.DateTime)).Value = this.Start;
cmd.Parameters.Add( new MySqlParameter("t_finish", MySqlDbType.DateTime)).Value = this.Finish;
cmd.Parameters.Add( new MySqlParameter("r_id", MySqlDbType.Int32)).Value = this.ResourceId;
conn.Open();
cmd.ExecuteNonQuery();
conn.Clone();
}
示例11: LoadEasyData
private void LoadEasyData()
{
MySqlConnection connection = new MySqlConnection(MyConnectionString);
connection.Open();
try
{
cmd = connection.CreateCommand();
cmd.CommandText = "SELECT * FROM easy";
MySqlDataAdapter adapt = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapt.Fill(ds);
history.dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
catch (Exception)
{
throw;
}
finally
{
if (connection.State == ConnectionState.Open)
{
connection.Clone();
}
}
}
示例12: Update
public void Update()
{
MySqlConnection conn = new MySqlConnection(Globals.ConnectionString);
MySqlCommand cmd = new MySqlCommand("update resources set [email protected], [email protected] where [email protected]", conn);
cmd.Parameters.Add( new MySqlParameter("id", MySqlDbType.Int32)).Value = this.Id;
cmd.Parameters.Add( new MySqlParameter("name", MySqlDbType.VarChar)).Value = this.Name;
cmd.Parameters.Add( new MySqlParameter("active", MySqlDbType.Bit)).Value = this.Active;
conn.Open();
cmd.ExecuteNonQuery();
conn.Clone();
}
示例13: comboSave
public bool comboSave(ArrayList delSqls, string itemMapSql, ArrayList mapSetSqls)
{
MySqlCommand mySqlCmd = new MySqlCommand();
MySqlConnection mySqlCon = null;
try
{
using (mySqlCon = new MySqlConnection(strConn))
{
if (mySqlCon != null && mySqlCon.State == ConnectionState.Closed)
{
mySqlCon.Open();
}
mySqlCmd.Connection = mySqlCon;
mySqlCmd.Transaction = mySqlCon.BeginTransaction();
mySqlCmd.CommandType = System.Data.CommandType.Text;
//删除原有对照
if (delSqls != null && delSqls.Count > 0)
{
foreach (var item in delSqls)
{
mySqlCmd.CommandText = item.ToString();
mySqlCmd.ExecuteNonQuery();
}
}
//保存ProductItemMap并返回主键
mySqlCmd.CommandText = itemMapSql;
int rid = Convert.ToInt32(mySqlCmd.ExecuteScalar());
//保存ProductMapSet
if (mapSetSqls != null && mapSetSqls.Count > 0)
{
foreach (var item in mapSetSqls)
{
mySqlCmd.CommandText = string.Format(item.ToString(), rid);
mySqlCmd.ExecuteNonQuery();
}
}
mySqlCmd.Transaction.Commit();
return true;
}
}
catch (Exception ex)
{
mySqlCmd.Transaction.Rollback();
throw new Exception("ProductItemMapDao.comboSave(ArrayList delSqls, string itemMapSql, ArrayList mapSetSqls)-->" + ex.Message, ex);
}
finally
{
if (mySqlCon != null && mySqlCon.State == ConnectionState.Open)
{
mySqlCon.Clone();
}
}
}
示例14: GetTable
private DataTable GetTable(string sql)
{
using (MySqlConnection connection = new MySqlConnection("server=localhost;user=root;database=lzbankdatabase;port=3306;password=root;"))
{
DataSet ds = new DataSet();
connection.Open();
try
{
MySqlDataAdapter da = new MySqlDataAdapter();
MySqlCommand cmd = new MySqlCommand(sql, connection);
cmd.CommandTimeout = 600;
da.SelectCommand = cmd;
da.Fill(ds, "ds");
}
catch
{ }
connection.Clone();
return ds.Tables[0];
}
}
示例15: Save
public void Save()
{
MySqlConnection conn = new MySqlConnection(Globals.ConnectionString);
MySqlCommand cmd = new MySqlCommand("insert into schedule (t_id, t_start, t_finish, r_id) values (@t_id, @t_start, @t_finish, @r_id)", conn);
cmd.Parameters.Add( new MySqlParameter("t_id", MySqlDbType.Int32)).Value = this.TaskId;
cmd.Parameters.Add( new MySqlParameter("t_start", MySqlDbType.DateTime)).Value = this.Start;
cmd.Parameters.Add( new MySqlParameter("t_finish", MySqlDbType.DateTime)).Value = this.Finish;
cmd.Parameters.Add( new MySqlParameter("r_id", MySqlDbType.Int32)).Value = this.ResourceId;
conn.Open();
cmd.ExecuteNonQuery();
conn.Clone();
}