当前位置: 首页>>代码示例>>C#>>正文


C# MySqlConnection.Close方法代码示例

本文整理汇总了C#中MySql.Data.MySqlClient.MySqlConnection.Close方法的典型用法代码示例。如果您正苦于以下问题:C# MySqlConnection.Close方法的具体用法?C# MySqlConnection.Close怎么用?C# MySqlConnection.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MySql.Data.MySqlClient.MySqlConnection的用法示例。


在下文中一共展示了MySqlConnection.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: addBussesToDB

        public static int addBussesToDB(List<string> bussesToAdd)
        {
            using (var connection = new MySqlConnection(DBConnection.getConnectionString()))
            {
                using (var cmd = connection.CreateCommand())
                {
                    try
                    {
                        foreach (var bus in bussesToAdd)
                        {
                            cmd.CommandText = string.Format("INSERT INTO Bus (ID, IsDescending, fk_BusRoute) " +
                                                            "VALUES({0}, null, null)", bus);

                            connection.Open();
                            cmd.ExecuteNonQuery();
                            connection.Close();
                        }
                        return 0;
                    }
                    catch (Exception e)
                    {
                        if (connection.State == System.Data.ConnectionState.Open)
                            connection.Close();
                        Debug.WriteLine(e.Message);
                        if (e.Message == "Unable to connect to any of the specified MySQL hosts.")
                            return -3;
                        else
                            return -1;
                    }
                }
            }
        }
开发者ID:ChristofferW,项目名称:Track-A-Bus,代码行数:32,代码来源:DBConnection.cs

示例2: CreateBank

        public int CreateBank(Bank b)
        {
            int ret = 0;
            using (connect = new MySqlConnection(_connectionString))
            {
                connect.Open();
                using (MySqlTransaction transaction = connect.BeginTransaction())
                {

                    try
                    {
                        string query = "NewBank";
                        var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };

                        cmd.Parameters.AddWithValue("SortCode", b.SortCode);
                        cmd.Parameters.AddWithValue("AccountNumber", b.ID);

                        ret = int.Parse(cmd.ExecuteScalar().ToString());

                        transaction.Commit();

                        connect.Close();
                    }
                    catch (InvalidOperationException ioException)
                    {
                        transaction.Rollback();
                        connect.Close();
                    }
                }
            }
            return ret;
        }
开发者ID:campbellre,项目名称:TWART,代码行数:32,代码来源:BankingModel.cs

示例3: GetAllBusStops

        public static List<BusStops> GetAllBusStops()
        {
            string ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["TrackABus"].ConnectionString;
            using (var connection = new MySqlConnection(ConnectionString))
            {
                using (var cmd = connection.CreateCommand())
                {
                    try
                    {
                        var stops = new List<BusStops>();
                        connection.Open();
                        cmd.CommandText = "SELECT StopName FROM BusStop;";
                        var read = cmd.ExecuteReader();

                        while (read.Read())
                        {
                            stops.Add(new BusStops(){busStopNames = read.GetString(0)});
                        }
                        read.Close();
                        connection.Close();

                        return stops;
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e.Message);
                        connection.Close();
                        return null;
                    }
                }
            }
        }
开发者ID:ChristofferW,项目名称:Track-A-Bus,代码行数:32,代码来源:BusStops.cs

示例4: ChangePassword

        public void ChangePassword(User u, String password)
        {
            using (connect = new MySqlConnection(_connectionString))
            {
                connect.Open();
                using (MySqlTransaction transaction = connect.BeginTransaction())
                {

                    try
                    {
                        string query = "ChangePassword";
                        var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };

                        cmd.Parameters.AddWithValue("pUID", u.username);
                        cmd.Parameters.AddWithValue("pPwd", password);

                        cmd.ExecuteNonQuery();

                        transaction.Commit();

                        connect.Close();
                    }
                    catch (InvalidOperationException ioException)
                    {
                        transaction.Rollback();

                        connect.Close();
                    }
                }
            }
        }
开发者ID:campbellre,项目名称:TWART,代码行数:31,代码来源:LoginModel.cs

示例5: timer1_Tick

        private void timer1_Tick(object sender, EventArgs e)
        {
            MySqlConnection cn = new MySqlConnection("server=localhost;user id=root; database=proyecto2; password=");
            this.progressBar1.Increment(1);
            if (progressBar1.Value == 100)
            {
                timer1.Stop();
                cn.Open();
                MySqlCommand cmd = new MySqlCommand("SELECT user_id FROM vs_users", cn);
                MySqlDataAdapter da = new MySqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);

                if (dt.Rows.Count > 0)
                {

                    login entrada = new login();
                    entrada.Show();
                    this.Hide();
                    cn.Close();
                }
                else
                {
                    registro entrada = new registro();
                    entrada.Show();
                    this.Hide();
                    cn.Close();
                }

            }
        }
开发者ID:jesusfsg06,项目名称:Proyecto-de-Dios,代码行数:31,代码来源:splash.cs

示例6: MySqlUtility

        public MySqlUtility(string csMySqlDB)
        {
            try
            {
                this.csConnectionString = csMySqlDB;

                oMySqlConnection = new MySqlConnection(csMySqlDB);

                //Make sure we can connect
                oMySqlConnection.Open();
                oMySqlConnection.Close();

            }
            catch (Exception ex)
            {
                throw new Exception("Error throw when trying to generate MySQL connection using the supplied connection string. See Inner Exception for details", ex);
            }
            finally
            {
                if (oMySqlConnection != null)
                {
                    if (oMySqlConnection.State == System.Data.ConnectionState.Open)
                    {
                        oMySqlConnection.Close();
                    }
                }
            }
        }
开发者ID:jordanburnam,项目名称:MySQLUtilities,代码行数:28,代码来源:MySqlUtility.cs

示例7: InertNews

        internal void InertNews(News news)
        {
            string sql = string.Format("insert into topic set date='{0}',url='{1}',place='{2}',level='{3}',reason='{4}',code='{5}',area_id='{6}'", news.Date, news.Detail_Url, news.Place, news.Level, news.Reason,news.Only,news.Area_Id);
            string error = null;
            MySqlConnection conn = null;
            try
            {
                conn = new MySqlConnection(connStr);
                conn.Open();
                MySqlDataAdapter adapter = new MySqlDataAdapter(sql, conn);
                // 创建DataSet,用于存储数据.
                DataSet testDataSet = new DataSet();
                // 执行查询,并将数据导入DataSet.
                adapter.Fill(testDataSet, "result_data");
                conn.Close();
                Console.WriteLine(news.Place+"--"+news.Reason);
            }
            catch (Exception e)
            {
                conn.Close();
                error = e.Message;
                Console.WriteLine("insert Topic error------>{0}", error);

            }
        }
开发者ID:heavenlw,项目名称:Awol,代码行数:25,代码来源:MysqlHelper.cs

示例8: EditSpecification

        public void EditSpecification(Specification s)
        {
            using (connect = new MySqlConnection(_connectionString))
            {
                connect.Open();
                using (MySqlTransaction transaction = connect.BeginTransaction())
                {

                    try
                    {
                        string query = "EditPackageSpecification";
                        var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };

                        cmd.Parameters.AddWithValue("SpecificationID", s.ID);
                        cmd.Parameters.AddWithValue("PWeight", s.Weight);
                        cmd.Parameters.AddWithValue("DeimensionHeight", s.Height);
                        cmd.Parameters.AddWithValue("DimensionWidth", s.Width);
                        cmd.Parameters.AddWithValue("DimensionLength", s.Length);

                        cmd.ExecuteNonQuery();

                        connect.Close();
                    }
                    catch (InvalidOperationException ioException)
                    {
                        connect.Close();
                    }
                }
            }
        }
开发者ID:campbellre,项目名称:TWART,代码行数:30,代码来源:SpecificationModel.cs

示例9: alterUser

        public void alterUser(TextBox textBoxGammelPassord, TextBox textBoxEpost, TextBox textBoxNyPassord, TextBox textBoxAdresse, TextBox textBoxTelefon, TextBox textBoxID, String bondeID)
        {
            String dbconnect = myconnectionstring;
            MySqlConnection dbconn = new MySqlConnection(dbconnect);

            if (textBoxGammelPassord.Text == gammeltpassordLocal)
            {
                MySqlCommand cmd = dbconn.CreateCommand();
                cmd.CommandText = "UPDATE login SET epost='" + textBoxEpost.Text + "', passord= '" + textBoxNyPassord.Text + "'WHERE bondeID= '" + bondeID + "'";
                dbconn.Open();
                cmd.ExecuteNonQuery();
                dbconn.Close();

                MySqlCommand cmd2 = dbconn.CreateCommand();
                cmd2.CommandText = "UPDATE Kontakt SET adresse= '" + textBoxAdresse.Text + "', telefonnr= '" + textBoxTelefon.Text + "' WHERE bondeID= '" + bondeID + "'";
                dbconn.Open();
                cmd2.ExecuteNonQuery();
                dbconn.Close();

                MessageBox.Show(textBoxTelefon.Text);
                getinfobruker(textBoxGammelPassord,  textBoxEpost,  textBoxNyPassord,  textBoxAdresse,  textBoxTelefon ,textBoxID, bondeID);
            }
            else
            {
                MessageBox.Show("Feil passord");
            }
        }
开发者ID:kwrl,项目名称:Insheeption1,代码行数:27,代码来源:Oversikt.cs

示例10: checkLogin

        private bool checkLogin(string username, string pass)
        {
            try
            {
                string mcon = "datasource=mysql.cc.puv.fi;port=3306;username=e1200641;password=bXk9fEzVExXW";
                string Query = "select * from e1200641_netExam.login where username=" + username + " and passwd=" + pass;
                MySqlConnection MyConn = new MySqlConnection(mcon);
                MySqlCommand MyCommand = new MySqlCommand(Query, MyConn);
                MySqlDataReader MyReader;
                MyConn.Open();
                MyReader = MyCommand.ExecuteReader();

                if (MyReader.Read())
                {
                    MyConn.Close();
                    return true;
                }
                else
                {
                    MyConn.Close();
                    return true;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return true;
            }
        }
开发者ID:klimskuridin,项目名称:vamk_csharp,代码行数:29,代码来源:LoginForm.cs

示例11: DeleteSpecification

        public void DeleteSpecification(int ID)
        {
            using (connect = new MySqlConnection(_connectionString))
            {
                connect.Open();
                using (MySqlTransaction transaction = connect.BeginTransaction())
                {

                    try
                    {
                        string query = "DeletePackageSpecification";
                        var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };

                        cmd.Parameters.AddWithValue("SpecificationID", ID);

                        cmd.ExecuteNonQuery();

                        connect.Close();
                    }
                    catch (InvalidOperationException ioException)
                    {
                        connect.Close();
                    }
                }
            }
        }
开发者ID:campbellre,项目名称:TWART,代码行数:26,代码来源:SpecificationModel.cs

示例12: 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;
        }
开发者ID:andyshao,项目名称:aushelper,代码行数:30,代码来源:DataService.cs

示例13: CreatePackage

        public int CreatePackage(Package p)
        {
            int ret = 0;
            using (connect = new MySqlConnection(_connectionString))
            {
                connect.Open();
                using (MySqlTransaction transaction = connect.BeginTransaction())
                {
                    try
                    {
                        string query = "NewPackage";
                        var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };

                        cmd.Parameters.AddWithValue("SpecificationID", p.SpecificationID);
                        cmd.Parameters.AddWithValue("GoodsID", p.GoodsID);

                        ret = int.Parse(cmd.ExecuteScalar().ToString());

                        transaction.Commit();

                        connect.Close();
                    }
                    catch (InvalidOperationException ioException)
                    {
                        transaction.Rollback();
                        connect.Close();
                    }
                }
            }
            return ret;
        }
开发者ID:campbellre,项目名称:TWART,代码行数:31,代码来源:PackageModel.cs

示例14: CreateAccountType

        public int CreateAccountType(Account_Type a)
        {
            int ret = 0;
            using (connect = new MySqlConnection(_connectionString))
            {
                connect.Open();
                using (MySqlTransaction transaction = connect.BeginTransaction())
                {
                    try
                    {
                        string query = "NewAccountType";
                        var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };

                        cmd.Parameters.AddWithValue("AccountName", a.Name);
                        cmd.Parameters.AddWithValue("PBenifit", a.Benefit);
                        cmd.Parameters.AddWithValue("PCost", a.Cost);

                        ret = int.Parse(cmd.ExecuteScalar().ToString());

                        transaction.Commit();

                        connect.Close();
                    }
                    catch (InvalidOperationException ioException)
                    {
                        transaction.Rollback();
                        connect.Close();
                    }
                }
            }
            return ret;
        }
开发者ID:campbellre,项目名称:TWART,代码行数:32,代码来源:AccountTypeModel.cs

示例15: Main

	static void Main()
	{
		string cs = @"server=localhost;port=9306;userid=root;password=;database=testdb";
		MySqlConnection conn = null;
		try
		{
			conn = new MySqlConnection(cs);
			conn.Open();

			MySqlCommand cmd = new MySqlCommand("SELECT * FROM rt", conn);
			MySqlDataReader r;
			r = cmd.ExecuteReader();

			while(r.Read())
			{
				Console.WriteLine(
					r.GetString(0) + " | " +
					r.GetString(1) + " | " +
					r.GetString(2) + " | " +
					r.GetString(3));
			}
			r.Close();
			conn.Close();
		} catch (MySqlException ex)
		{
			Console.WriteLine("Error: {0}", ex.ToString());
		} finally
		{
			if (conn != null)
				conn.Close();
		}
	}
开发者ID:jianzchen,项目名称:sphinx,代码行数:32,代码来源:qltest.cs


注:本文中的MySql.Data.MySqlClient.MySqlConnection.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。