當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。