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


C# System.Close方法代码示例

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


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

示例1: Exists

 public static bool Exists(System.Data.SqlClient.SqlConnection connection, string category_name, out bool exists, out string message)
 {
     bool ret = false;
     exists = false;
     message = "";
     Guid cat_id = Guid.Empty;
     try
     {
         connection.Open();
         string sQuery = "SELECT CategoryID\n" +
                         "  FROM " + Categories.Table + "\n" +
                         " WHERE CategoryName = @Category";
         System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sQuery);
         cmd.Parameters.AddWithValue("@Category", category_name );
         cmd.Connection = connection;
         object res = cmd.ExecuteScalar();
         if (res != null && !System.Convert.IsDBNull(res)) cat_id = (Guid)res;
         connection.Close();
         exists = (cat_id != Guid.Empty);
         ret = true;
     }
     catch (System.Exception ex)
     {
         message = ex.Message;
     }
     finally
     {
         if (connection.State == System.Data.ConnectionState.Open) connection.Close();
     }
     return ret;
 }
开发者ID:Skydger,项目名称:vBudget,代码行数:31,代码来源:Categories.cs

示例2: ChangeProduct

        public static bool ChangeProduct( System.Data.SqlClient.SqlConnection connection,
                                          System.Data.SqlClient.SqlTransaction tran,
                                          object old_product_id, object new_product_id, out string error)
        {
            bool done = false;
            error = "";
            try
            {
                connection.Open();
                System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
                string query = "UPDATE Purchases.ReceiptContents SET ProductID = @NewProduct\n" +
                                "WHERE ProductID = @OldProduct";
                cmd.Parameters.AddWithValue("@NewProduct", new_product_id);
                cmd.Parameters.AddWithValue("@OldProduct", old_product_id);
                cmd.CommandTimeout = 0;
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.CommandText = query;
                cmd.Connection = connection;
                if (tran != null) cmd.Transaction = tran;
                cmd.ExecuteNonQuery();
                connection.Close();
                done = true;
            }
            catch (System.Exception ex)
            {
                error = ex.Message;
            }
            finally
            {
                if (connection.State == System.Data.ConnectionState.Open) connection.Close();
            }

            return done;
        }
开发者ID:Skydger,项目名称:vBudget,代码行数:34,代码来源:ReceiptContent.cs

示例3: Delete

 public static bool Delete(System.Data.SqlClient.SqlConnection connection, System.Data.DataRow row, out string message)
 {
     bool done = false;
     message = "";
     try
     {
         connection.Open();
         System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
         string sQuery = "DELETE FROM " + Categories.Table + "\n" +
                         " WHERE CategoryID = @CategoryID";
         cmd.Parameters.AddWithValue("@CategoryID", row["CategoryID"]);
         cmd.Connection = connection;
         cmd.CommandTimeout = 0;
         cmd.CommandType = System.Data.CommandType.Text;
         cmd.CommandText = sQuery;
         cmd.ExecuteNonQuery();
         connection.Close();
         done = true;
     }
     catch (System.Exception ex)
     {
         message = ex.Message;
     }
     finally
     {
         if (connection.State == System.Data.ConnectionState.Open) connection.Close();
     }
     return done;
 }
开发者ID:Skydger,项目名称:vBudget,代码行数:29,代码来源:Categories.cs

示例4: Delete

        /// <summary>
        /// �������� ������ � �� � ���������� �����
        /// </summary>
        /// <param name="connection">��������� � ��</param>
        /// <param name="row">������</param>
        /// <param name="message">�������� ��������� �� ������, ���� ����� ���������� ����</param>
        /// <returns>����� ���������� ������, ���� �� �������� ������; ���� - � ��������� ������</returns>
        public static bool Delete(System.Data.SqlClient.SqlConnection connection, System.Data.DataRow row, /*byte[] image,*/ out string message)
        {
            bool done = false;
            message = "";
            try{
                connection.Open();
                System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
                string sQuery = "IF EXISTS (SELECT DiscountCard\n" +
                                "             FROM Purchases.Receipts\n" +
                                "            WHERE Purchases.Receipts.DiscountCard = @CardID ) \n" +
                                "   UPDATE Purchases.DiscountCards\n" +
                                "      SET Expired = GETDATE()\n" +
                                "    WHERE CardID = @CardID\n" +
                                "ELSE\n" +
                                "   DELETE\n" +
                                "     FROM Purchases.DiscountCards\n" +
                                "    WHERE CardID = @CardID";

                cmd.Parameters.AddWithValue("@CardID", row["CardID"]);
                cmd.Connection = connection;
                cmd.CommandTimeout = 0;
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.CommandText = sQuery;
                cmd.ExecuteNonQuery();
                connection.Close();
                done = true;
            }catch (System.Exception ex){
                message = ex.Message;
            }finally{
                if (connection.State == System.Data.ConnectionState.Open) connection.Close();
            }
            return done;
        }
开发者ID:Skydger,项目名称:vBudget,代码行数:40,代码来源:DiscountCard.cs

示例5: Delete

 public static bool Delete(System.Data.SqlClient.SqlConnection connection,
                           System.Data.SqlClient.SqlTransaction tran,
                           System.Data.DataRow row, out string message)
 {
     bool done = false;
     message = "";
     try
     {
         connection.Open();
         System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
         string sQuery = "DELETE FROM Producer.Products\n" +
                         " WHERE ProductID = @ProductID";
         cmd.Parameters.AddWithValue("@ProductID", row["ProductID"]);
         cmd.Connection = connection;
         if (tran != null) cmd.Transaction = tran;
         cmd.CommandTimeout = 0;
         cmd.CommandType = System.Data.CommandType.Text;
         cmd.CommandText = sQuery;
         cmd.ExecuteNonQuery();
         connection.Close();
         done = true;
     }
     catch (System.Exception ex)
     {
         message = ex.Message;
     }
     finally
     {
         if (connection.State == System.Data.ConnectionState.Open) connection.Close();
     }
     return done;
 }
开发者ID:Skydger,项目名称:vBudget,代码行数:32,代码来源:Product.cs

示例6: Insert

 // Занесение новой записи в БД
 public static bool Insert(System.Data.SqlClient.SqlConnection connection, System.Data.DataRow row, out string message)
 {
     bool done = false;
     message = "";
     try{
         connection.Open();
         System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
         string sQuery = "INSERT INTO " + Maker.Table + "\n" +
                         "       (MakerID, Name, MakerCategory, Vendor, Address, Created, Updated)\n" +
                         "VALUES (@MakerID, @Name, @MakerCategory, @Vendor, @Address, GETDATE(), GETDATE())";
         cmd.Parameters.AddWithValue("@MakerID", row["MakerID"]);
         cmd.Parameters.AddWithValue("@Name", row["Name"]);
         cmd.Parameters.AddWithValue("@MakerCategory", row["MakerCategory"]);
         cmd.Parameters.AddWithValue("@Vendor", row["Vendor"]);
         cmd.Parameters.AddWithValue("@Address", row["Address"]);
         //cmd.Parameters.AddWithValue("@Created", row["Created"]);
         //cmd.Parameters.AddWithValue("@Updated", row["Updated"]);
         cmd.Connection = connection;
         cmd.CommandTimeout = 0;
         cmd.CommandType = System.Data.CommandType.Text;
         cmd.CommandText = sQuery;
         cmd.ExecuteNonQuery();
         connection.Close();
         done = true;
     }catch (System.Exception ex){
         message = ex.Message;
     }finally{
         if (connection.State == System.Data.ConnectionState.Open) connection.Close();
     }
     return done;
 }
开发者ID:Skydger,项目名称:vBudget,代码行数:32,代码来源:Maker.cs

示例7: Main

		public static void Main (string[] args)
		{


			MySqlConnection mySqlConnection= new MySqlConnection("" +
			                                                     "Server= localhost;Database=dbprueba;User ID = root; Password= sistemas"");

mySqlConnection.Open();	

Console.WriteLine ("Hello World!");

MySqlCommand mySqlCommand= mySqlConnection.CreateCommand();
mySqlCommand.CommandText= string.Format("insert into categoria(nombre)values ('{0}')", DateTime.Now);
mySqlCommand.ExecuteNonQuery;

mySqlCommand.CommandText= "select * from categoria";

MySqlDataReader mySqlDataReader= mySqlCommand.ExecuteReader();
Console.WriteLine("FieldCount={0}", mySqlDataReader.FieldCount);
for(int index=0; index < mySqlDataReader.FieldCount; index++)
Console.WriteLine("colum{0}={1}", indexer, mySqlDataReader.getName(indexer));

while(mySqlDataReader.Read()){
object id= mySqlDataReader["nombre"];
Console.WriteLine("id={0} nombre={1}", id , nombre);

mySqlDataReader.Close();


mySqlConnection.Close();
}
}
开发者ID:javidam,项目名称:Ad,代码行数:32,代码来源:Program.cs

示例8: CloseWindow

 public static bool CloseWindow(System.Windows.Window window)
 {
     if (window == null) return false;
     try { window.Close(); }
     catch { return false; }
     return true;
 }
开发者ID:Mikolaytis,项目名称:Mikolaytis,代码行数:7,代码来源:Try.cs

示例9: Header

            public Header(System.Data.SQLite.SQLiteConnection connection)
            {
                System.Collections.Hashtable hash = null;

                using (System.Data.SQLite.SQLiteCommand tSQLiteCommand = connection.CreateCommand())
                {

                    tSQLiteCommand.CommandText = clientBuildCommand;
                    using (System.Data.SQLite.SQLiteDataReader reader = tSQLiteCommand.ExecuteReader())
                    {
                        int total = reader.RecordsAffected;
                        hash = new System.Collections.Hashtable(total);
                        while (reader.Read())
                        {
                            hash[reader.GetString(0)] = reader.GetValue(1);
                        }
                        reader.Close();
                    }


                }

                clientBuild = int.Parse((string)hash["clientBuild"]);
                accountName = (string)hash["accountName"];
                realmname = (string)hash["realmName"];
                realmServer = (string)hash["realmServer"];


                connection.Close();
            }
开发者ID:RaptorFactor,项目名称:devmaximus,代码行数:30,代码来源:ReaderMaximusSQLite.cs

示例10: Load

        public static List<Employee> Load(System.IO.StreamReader stream)
        {
            List<Employee> list = new List<Employee>();

            try
            {
                while (stream.Peek() >= 0)
                {
                    string line = stream.ReadLine();

                    string[] values = line.Split(',');
                    Employee employee = new Employee();
                    employee.FirstName = values[0];
                    employee.LastName = values[1];
                    employee.Email = values[2];

                    list.Add(employee);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                stream.Close();
            }

            return list;
        }
开发者ID:thinkAmi,项目名称:9784774153773_JUnit,代码行数:30,代码来源:Employee.cs

示例11: PurgeSingleFile

 private void PurgeSingleFile(System.IO.Stream stream, string filename)
 {
     if (stream != null)
         stream.Close();
     if (System.IO.File.Exists(filename))
         System.IO.File.Delete(filename);
 }
开发者ID:RemiGaudin,项目名称:quickfixn,代码行数:7,代码来源:FileStore.cs

示例12: InsertAndReturnNewID

        protected override int InsertAndReturnNewID(System.Data.IDbConnection conn, IQMap.ISqlQuery query, System.Data.IDbTransaction transaction = null, System.Data.CommandBehavior commandBehavior = System.Data.CommandBehavior.Default)
        {
            //var newQuery= new SqlQueryDef(, query.Parameters);

            var newQ= new IQMap.SqlQueryBuilder.Impl.SqlQueryDef( query.GetQuery() + "", query.Parameters);
            int result = 0;

            using (var cmd = GetCommand(conn, newQ, transaction))
            {

                ExecuteSqlFinal(new Action(() =>
                {
                    cmd.ExecuteNonQuery();
                }));

                cmd.Parameters.Clear();
                cmd.CommandText = "SELECT @@IDENTITY;";
                result = Convert.ToInt32(cmd.ExecuteScalar());
                cmd.Dispose();
            }
            if (commandBehavior == CommandBehavior.CloseConnection)
            {
                conn.Close();
            }
            OnQueryComplete();
            return result;
        }
开发者ID:jamietre,项目名称:IQMap,代码行数:27,代码来源:SQLCompactEditionController.cs

示例13: Close

		/// <summary>
		/// [可重入]关闭连接
		/// </summary>
		/// <param name="Connection"></param>
		public static void Close(System.Data.Common.DbConnection Connection)
		{
			if (Connection != null && Connection.State != System.Data.ConnectionState.Closed)
			{
				Connection.Close();
			}
		}
开发者ID:lujinlong,项目名称:Apq,代码行数:11,代码来源:DbConnectionHelper.cs

示例14: CloseMessage

 /// <summary>
 /// Function for close message
 /// </summary>
 /// <param name="frm"></param>
 public static void CloseMessage(System.Windows.Forms.Form frm)
 {
     if ((MessageBox.Show("Are you sure to exit ? ", "OpenMiracle", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) == DialogResult.Yes)
     {
         frm.Close();
     }
 }
开发者ID:JaseelAM,项目名称:OpenMiracle-Three-Tier,代码行数:11,代码来源:Messages.cs

示例15: WriteToStream

        public static void WriteToStream(System.IO.Stream stream, string data)
        {
            byte[] buffer = System.Text.Encoding.UTF8.GetBytes(data);

            stream.Write(buffer, 0, buffer.Length);
            stream.Close();
        }
开发者ID:flipback,项目名称:Galilei,代码行数:7,代码来源:Helper.cs


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