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


C# SqlCommand.Dispose方法代码示例

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


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

示例1: DeleteAudit

 public void DeleteAudit(int AuditID)
 {
     string SQL = "DELETE FROM tblAuditTrail WHERE AuditID = '" + AuditID + "'";
     SqlCommand scmDelete = new SqlCommand(SQL, con);
     scmDelete.ExecuteNonQuery();
     scmDelete.Dispose();
 }
开发者ID:pageman,项目名称:TransactionSystem,代码行数:7,代码来源:SQLLibrary.cs

示例2: BasicParallelTest

        private void BasicParallelTest(string connectionString, string tempTableName)
        {
            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlTransaction trans1 = connection.BeginTransaction();
                SqlTransaction trans2 = connection.BeginTransaction();
                SqlTransaction trans3 = connection.BeginTransaction();

                SqlCommand com1 = new SqlCommand("select top 1 au_id from " + tempTableName, connection);
                com1.Transaction = trans1;
                com1.ExecuteNonQuery();

                SqlCommand com2 = new SqlCommand("select top 1 au_id from " + tempTableName, connection);
                com2.Transaction = trans2;
                com2.ExecuteNonQuery();

                SqlCommand com3 = new SqlCommand("select top 1 au_id from " + tempTableName, connection);
                com3.Transaction = trans3;
                com3.ExecuteNonQuery();

                trans1.Rollback();
                trans2.Rollback();
                trans3.Rollback();

                com1.Dispose();
                com2.Dispose();
                com3.Dispose();
            }
        }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:30,代码来源:ParallelTransactionsTest.cs

示例3: Method1

 public void Method1(string connection,string command)
 {
     SqlConnection conn = null;
     try
     {
         conn = new SqlConnection(connection);
         //do something
         SqlCommand comm =null;
         try
         {
             comm = new SqlCommand(command);
             //do something
         }
         finally
         {
             if (comm != null)
                 comm.Dispose();
         }
     }
     finally
     {
         if (conn != null)
             conn.Dispose();
     }
 }
开发者ID:kaplunov93,项目名称:EffectiveCsharp,代码行数:25,代码来源:Disposing.cs

示例4: AddOrder

 public void AddOrder(int Quantity, string Username, string ProductName, string OrderStatus, string Contact, string Address)
 {
     string SQL = "INSERT INTO tblOrders (Quantity, Username, ProductName, Date, OrderStatus, Contact, Address) VALUES " +
         "(" + "'" + Quantity + "'" + ", " + "'" + Username + "'" + ", " + "'" + ProductName + "'" + ", " + "GETDATE()" + ", " + "'" + OrderStatus + "'" + ", " + "'" + Contact + "'" + ", " + "'" + Address + "'" + ")";
     SqlCommand scmAdd = new SqlCommand(SQL, con);
     scmAdd.ExecuteNonQuery();
     scmAdd.Dispose();
 }
开发者ID:pageman,项目名称:TransactionSystem,代码行数:8,代码来源:SQLLibrary.cs

示例5: Register

 public void Register(string Name, string UserName, string Password, string UserType)
 {
     string SQL = "INSERT INTO TblUser (Name, UserName, Password, UserType) VALUES " +
         "(" + "'" + Name + "'" + ", " + "'" + UserName + "'" + ", " + "'" + Password + "'" + ", " + "'" + UserType + "'" + ")";
     SqlCommand scmAdd = new SqlCommand(SQL, con);
     scmAdd.ExecuteNonQuery();
     scmAdd.Dispose();
 }
开发者ID:pageman,项目名称:TransactionSystem,代码行数:8,代码来源:SQLLibrary.cs

示例6: AuditTrail

 public void AuditTrail(int UID, string Action)
 {
     string SQL = "INSERT INTO tblAuditTrail (UserID, Action, DateAction) VALUES " +
     "(" + UID + ",'" +
     Action + "', GETDATE())";
     SqlCommand scmAdd = new SqlCommand(SQL, con);
     scmAdd.ExecuteNonQuery();
     scmAdd.Dispose();
 }
开发者ID:pageman,项目名称:TransactionSystem,代码行数:9,代码来源:SQLLibrary.cs

示例7: EditOrder

 public void EditOrder(int OrderID, string ProductName, int Quantity, string Contact, string Address)
 {
     string SQL = "UPDATE tblOrders SET" +
     " ProductName = '" + ProductName + "', " +
     "Quantity = '" + Quantity + "', " +
     "Contact = '" + Contact + "', " +
     "Address = '" + Address + "'" +
     "WHERE OrderID = '" + OrderID + "'";
     SqlCommand scmEdit = new SqlCommand(SQL, con);
     scmEdit.ExecuteNonQuery();
     scmEdit.Dispose();
 }
开发者ID:pageman,项目名称:TransactionSystem,代码行数:12,代码来源:SQLLibrary.cs

示例8: MultipleCommands

    public static MultipleCommands(string[] cmds, SqlConnection scon)
    {
        SqlCommand cmd = new SqlCommand();
        SqlCommand.Connection = scon;

        try
        {
            foreach (string c in cmds)
            {
                try
                {
                    scon.Open()
                    cmd.CommandText = c;
                    cmd.ExecuteNonQuery();
                    cmd.CommandText = "";
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    scon.Close();
                    scon.Dispose();
                }
            }
            return 1;
        }
        catch (Exception ex)
        {
            throw ex;
            return 0;
        }
        finally
        {
            cmd.Dispose()
        }
    }
开发者ID:tmmtsmith,项目名称:CSharpDOTNET,代码行数:38,代码来源:Classes.cs

示例9: EditProduct

 public void EditProduct(int ProductID, string ProductName, int SoH, int SR, string Description, int Price, int NumberSold, string ExpiryDate)
 {
     string SQL = "UPDATE tblProducts SET " +
     "ProductName = '" + ProductName + "', " +
     "SoH = '" + SoH + "', " +
     "SR = '" + SR + "', " +
     "Description = '" + Description + "', " +
     "Price = '" + Price + "', " +
     "NumberSold = '" + NumberSold + "', " +
     "ExpiryDate = '" + ExpiryDate + "'" +
     "WHERE ProductID = '" + ProductID + "'";
     SqlCommand scmEdit = new SqlCommand(SQL, con);
     scmEdit.ExecuteNonQuery();
     scmEdit.Dispose();
 }
开发者ID:pageman,项目名称:TransactionSystem,代码行数:15,代码来源:SQLLibrary.cs

示例10: MultipleExecutesInSameTransactionTest

        private void MultipleExecutesInSameTransactionTest(string connectionString, string tempTableName)
        {
            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlTransaction trans1 = connection.BeginTransaction();
                SqlTransaction trans2 = connection.BeginTransaction();
                SqlTransaction trans3 = connection.BeginTransaction();

                SqlCommand com1 = new SqlCommand("select top 1 au_id from " + tempTableName, connection);
                com1.Transaction = trans1;
                com1.ExecuteNonQuery();

                SqlCommand com2 = new SqlCommand("select top 1 au_id from " + tempTableName, connection);
                com2.Transaction = trans2;
                com2.ExecuteNonQuery();

                SqlCommand com3 = new SqlCommand("select top 1 au_id from " + tempTableName, connection);
                com3.Transaction = trans3;
                com3.ExecuteNonQuery();

                trans1.Rollback();
                trans2.Rollback();
                trans3.Rollback();

                com1.Dispose();
                com2.Dispose();
                com3.Dispose();

                SqlCommand com4 = new SqlCommand("select top 1 au_id from " + tempTableName, connection);
                com4.Transaction = trans1;
                SqlDataReader reader4 = com4.ExecuteReader();
                reader4.Dispose();
                com4.Dispose();

                trans1.Rollback();
            }
        }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:38,代码来源:ParallelTransactionsTest.cs

示例11: ReceiveOperatorInfo

            //填充操作员信息 LogOperatorID
            public static void ReceiveOperatorInfo(string userid)
            {
                //根据LogOperator返回雇员信息
                opinfo.OpID = userid;
                System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();
                conn.ConnectionString = ConnStr;
                try
                {
                    SqlCommand selectCMD = new SqlCommand("SELECT * FROM Operator where OperatorID='" + userid + "'", conn);
                    selectCMD.CommandTimeout = 30;
                    SqlDataAdapter dbDA = new SqlDataAdapter();
                    dbDA.SelectCommand = selectCMD;
                    conn.Open();
                    DataSet dbDS = new DataSet();
                    dbDA.Fill(dbDS, "t");
                    //获得 EmployeeID->empno
                    string empno;
                    empno = dbDS.Tables[0].Rows[0]["EmpID"].ToString();
                    opinfo.EmpID = empno;
                    //根据EmpNo返回EmployeeName 和 Department
                    selectCMD.Dispose();
                    selectCMD.Connection = conn;
                    selectCMD.CommandText = "SELECT * FROM Employee where EmpID='" + empno + "'";
                    dbDA.SelectCommand = selectCMD;
                    dbDS.Clear();
                    dbDA.Fill(dbDS, "t");
                    opinfo.EmployeeName = dbDS.Tables[0].Rows[0]["name"].ToString();

                    //返回部门名称
                    string depno;
                    depno = dbDS.Tables[0].Rows[0]["depcode"].ToString();
                    selectCMD.Dispose();
                    selectCMD.Connection = conn;
                    selectCMD.CommandText = "SELECT * FROM Department where depcode='" + depno + "'";
                    dbDA.SelectCommand = selectCMD;
                    dbDS.Clear();
                    dbDA.Fill(dbDS, "t");

                    opinfo.Department = dbDS.Tables[0].Rows[0]["deptname"].ToString();

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    conn.Close();
                }
            }
开发者ID:uwitec,项目名称:carrey-rms,代码行数:51,代码来源:rms_var.cs

示例12: updatedata

        private void updatedata()
        {
            //use filestream object to read the image.

            //read to the full length of image to a byte array.

            //add this byte as an oracle parameter and insert it into database.

            try
            {

                //proceed only when the image has a valid path

                if (imagename != "")
                {

                    FileStream fs;

                    fs = new FileStream(@imagename, FileMode.Open, FileAccess.Read);

                    //a byte array to read the image

                    byte[] picbyte = new byte[fs.Length];

                    fs.Read(picbyte, 0, System.Convert.ToInt32(fs.Length));

                    fs.Close();

                    //open the database using odp.net and insert the data

                    string connstr = @"Data Source=.;Initial Catalog=TestImage;Persist Security Info=True;User ID=sa";

                    SqlConnection conn = new SqlConnection(connstr);

                    conn.Open();

                    string query;

                    query = "insert into test_table(id_image,pic) values(" +
                    textBox1.Text + "," + " @pic)";

                    SqlParameter picparameter = new SqlParameter();

                    picparameter.SqlDbType = SqlDbType.Image;

                    picparameter.ParameterName = "pic";

                    picparameter.Value = picbyte;

                    SqlCommand cmd = new SqlCommand(query, conn);

                    cmd.Parameters.Add(picparameter);

                    cmd.ExecuteNonQuery();

                    MessageBox.Show("Image Added");

                    cmd.Dispose();

                    conn.Close();

                    conn.Dispose();

                    Connection();

                }

            }

            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);

            }
        }
开发者ID:qwerfaqs,项目名称:jacintodotnet,代码行数:76,代码来源:Prueba.cs

示例13: AddProduct

 public void AddProduct(string ProductName, int SoH, int SR, string Description, int Price, int NumberSold, string ExpiryDate)
 {
     string SQL = "INSERT INTO tblProducts (ProductName, SoH, SR, Description, Price, NumberSold, ExpiryDate) VALUES " +
         "(" + "'" + ProductName + "'" + ", " + "'" + SoH + "'" + ", " + "'" + SR + "'" + ", " + "'" + Description + "'" + ", " + "'" + Price + "'" + ", " + "'" + NumberSold + "'" + ", " + "'" + ExpiryDate + "'" + ")";
     SqlCommand scmAdd = new SqlCommand(SQL, con);
     scmAdd.ExecuteNonQuery();
     scmAdd.Dispose();
 }
开发者ID:pageman,项目名称:TransactionSystem,代码行数:8,代码来源:SQLLibrary.cs

示例14: DeleteOrder

 public void DeleteOrder(int OrderID)
 {
     string SQL = "DELETE FROM tblOrders WHERE OrderID = '" + OrderID + "'";
     SqlCommand scmDelete = new SqlCommand(SQL, con);
     scmDelete.ExecuteNonQuery();
     scmDelete.Dispose();
 }
开发者ID:pageman,项目名称:TransactionSystem,代码行数:7,代码来源:SQLLibrary.cs

示例15: OrderStatus

 public void OrderStatus(int OrderID, string OrderStatus)
 {
     string SQL = "UPDATE tblOrders SET" +
     " OrderStatus = '" + OrderStatus + "'" +
     "WHERE OrderID = '" + OrderID + "'";
     SqlCommand scmEdit = new SqlCommand(SQL, con);
     scmEdit.ExecuteNonQuery();
     scmEdit.Dispose();
 }
开发者ID:pageman,项目名称:TransactionSystem,代码行数:9,代码来源:SQLLibrary.cs


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