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


C# OleDbCommand.Dispose方法代码示例

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


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

示例1: SaveRecord

        public static int SaveRecord(string sql)
        {
            const int rv = 0;
            try
            {
                string connectionString = ConfigurationManager.ConnectionStrings["LA3Access"].ConnectionString;
                using (var conn = new OleDbConnection(connectionString))
                {
                    conn.Open();
                    var cmGetID = new OleDbCommand("SELECT @@IDENTITY", conn);
                    var comm = new OleDbCommand(sql, conn) { CommandType = CommandType.Text };
                    comm.ExecuteNonQuery();

                    var ds = new DataSet();
                    var adapt = new OleDbDataAdapter(cmGetID);
                    adapt.Fill(ds);
                    adapt.Dispose();
                    cmGetID.Dispose();

                    return int.Parse(ds.Tables[0].Rows[0][0].ToString());

                }
            }
            catch (Exception)
            {
            }
            return rv;
        }
开发者ID:FuriousLogic,项目名称:LA3_DataTransfer,代码行数:28,代码来源:CoreFunctions.cs

示例2: btnOk_Click

 private void btnOk_Click(object sender, EventArgs e)
 {
     string sql = "select * from [staff] where [scode][email protected] and [password][email protected]";
     OleDbCommand cmd = new OleDbCommand(sql, DataAccess.getInstance().getDataConnection());
     cmd.Parameters.AddWithValue("scode", ((StaffModel) cboUsername.SelectedValue).Value);
     cmd.Parameters.AddWithValue("password", txtPassword.Text);
     OleDbDataReader rdr = cmd.ExecuteReader();
     if (rdr.Read())
     {
         if(!rdr.GetBoolean(rdr.GetOrdinal("isactive")))
         {
             MessageBox.Show("Your account has been deactivated. Please consult your administration regarding this");
             rdr.Close();
             cmd.Dispose();
             return;
         }
         Program.loginStaff = new StaffModel(rdr.GetInt32(rdr.GetOrdinal("staffno")), rdr.GetString(rdr.GetOrdinal("scode")), rdr.GetString(rdr.GetOrdinal("sname")), "");
         rdr.Close();
         cmd.Dispose();
         graceClose = true;
         Close();
     }
     else
     {
         MessageBox.Show("You have supply a wrong credential", Application.ProductName);
         return;
     }
 }
开发者ID:swdevbali,项目名称:Pimphony-Integration-Utility,代码行数:28,代码来源:LoginDialog.cs

示例3: IsValidModerator

        public bool IsValidModerator(string login, string password)
        {
            var conn =
                new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|Użytkownicy.accdb");
            var cmd = new OleDbCommand("SELECT [Login] FROM [Users] " + @"WHERE [Login] = @l AND [Hasło] = @p AND [Prawa] = @a") { Connection = conn };
            cmd.Parameters.Clear();
            cmd.Parameters.Add(new OleDbParameter("@l", OleDbType.VarWChar)).Value = login;
            cmd.Parameters.Add(new OleDbParameter("@p", OleDbType.VarWChar)).Value = password;
            cmd.Parameters.Add(new OleDbParameter("@a", OleDbType.VarWChar)).Value = "Moderator";
            conn.Open();

            var reader = cmd.ExecuteReader();

            if (reader != null && reader.HasRows)
            {
                reader.Dispose();
                cmd.Dispose();
                return true;
            }
            else
            {
                reader?.Dispose();
                cmd.Dispose();
                return false;
            }
        }
开发者ID:RobertPasternak,项目名称:Biblioteka-MVC5,代码行数:26,代码来源:LoginResponse.cs

示例4: RunQuery

        /// <summary>
        /// Executes an inline SQL statement and returns a data table.
        /// </summary>
        /// <param name="dbStatement">Inline SQL</param>
        /// <param name="connectionString">Connection string</param>
        /// <returns>Data table containing the return data</returns>
        public static DataTable RunQuery(string dbStatement, string connectionString)
        {
            OleDbConnection dbConnection = null;
            OleDbCommand dbCommand = null;
            OleDbDataAdapter adapter = null;
            DataTable dt = null;

            try
            {
                dbConnection = new OleDbConnection(connectionString);
                dbCommand = new OleDbCommand(dbStatement, dbConnection);
                dbCommand.CommandType = CommandType.Text;
                dbCommand.CommandTimeout = 600;

                adapter = new OleDbDataAdapter(dbCommand);
                dt = new DataTable();

                dbConnection.Open();
                adapter.Fill(dt);
                return dt;
            }
            finally
            {
                if (adapter != null)
                    adapter.Dispose();
                if (dbCommand != null)
                    dbCommand.Dispose();
                if (dbConnection != null)
                    dbConnection.Dispose();
            }
        }
开发者ID:jdwittenauer,项目名称:insight-net,代码行数:37,代码来源:OLEDBClient.cs

示例5: getSats

        //Retourne les stats
        public static Statistique getSats(int noJoueur)
        {
            Statistique stat = null;
            OleDbConnection connexion = new OleDbConnection(connBD);
            try
            {
                connexion.Open();
                commande = new OleDbCommand("SELECT * FROM tblStatistique WHERE [email protected]", connexion);
                commande.Parameters.Add("@noJoueur", OleDbType.Integer).Value = noJoueur;

                OleDbDataReader reader = commande.ExecuteReader();
                while (reader.Read())
                {
                    int nbGagne = reader["nbPartieGagne"] == DBNull.Value ? 0 : Convert.ToInt32(reader["nbPartieGagne"]);
                    int nbPerdu = reader["nbPartiePerdu"] == DBNull.Value ? 0 : Convert.ToInt32(reader["nbPartiePerdu"]);
                    int score = reader["score"] == DBNull.Value ? 0 : Convert.ToInt32(reader["score"]);
                    stat = new Statistique(nbGagne, nbPerdu, score);
                }

                return stat;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
                commande.Dispose();
                connexion.Close();
            }
        }
开发者ID:DiscanX,项目名称:TP3-evo,代码行数:32,代码来源:Utilitaire.cs

示例6: Button1_Click

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Session["oturumid"] == null)
                Response.Redirect("giris.aspx");
            else if (Session["oturumdurum"].ToString() == "1")
                Response.Redirect("adminpaneli.aspx");
            else
            {
                string fid = (sender as Button).CommandArgument;
                string kid = Session["oturumid"].ToString();
                string sepet = "";

                OleDbConnection cnn = new OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=" + Server.MapPath("App_Data/database.mdb"));
                cnn.Open();
                OleDbCommand cmd = new OleDbCommand("select sepet from uyeler where uyeid=" + kid, cnn);
                OleDbDataReader rdr = cmd.ExecuteReader();
                rdr.Read();
                sepet = rdr[0].ToString();
                if (sepet == "")
                    sepet = fid;
                else
                    sepet += "," + fid;

                cmd.Dispose();
                cmd = new OleDbCommand("update uyeler set sepet='" + sepet + "' where uyeid=" + kid, cnn);
                cmd.ExecuteNonQuery();
                cnn.Close();
                Session.Add("um", "Fotoğraf sepetinize eklendi. İyi alışverişler.");
                Response.Redirect("uyepaneli.aspx");
            }
        }
开发者ID:samikilic,项目名称:fotosale,代码行数:31,代码来源:fotografdetay.aspx.cs

示例7: btnNew_Click

        private void btnNew_Click( object sender, EventArgs e )
        {
            if( Program.UserType == UserType.Customer )
                return;

            AddDlg dlg = new AddDlg();
            if( dlg.ShowDialog( this ) != DialogResult.OK )
                return;

            RefillComboBoxes();

            OleDbCommand cmd = new OleDbCommand();
            cmd.CommandText = "select top 1 * from WedDress order by [ID] desc";
            cmd.Connection = Program.Database;
            cmd.CommandType = CommandType.Text;

            OleDbDataAdapter oda = new OleDbDataAdapter( cmd);
            DataTable dt = new DataTable();
            oda.Fill( dt );

            dsDress.Tables["WedDress"].Merge( dt );
            dt.Dispose();
            oda.Dispose();
            cmd.Dispose();
        }
开发者ID:mokacao,项目名称:backup,代码行数:25,代码来源:MainForm.cs

示例8: btnDel_Click

        private void btnDel_Click( object sender, EventArgs e )
        {
            if( Program.UserType != UserType.Admin )
                return;

            if( dataGridView.CurrentRow == null )
                return;

            int id = (int)dataGridView.CurrentRow.Cells[0].Value;
            DataTable dt = dsDress.Tables["WedDress"];
            DataRow[] rows = dt.Select( "[ID]=" + id );
            if( rows.GetLength( 0 ) <= 0 )
                return;

            if( MessageBox.Show( this, "��ȷʵҪɾ��ѡ���ķ�װ��?", Program.AppTitle,
                MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2 )
                == DialogResult.No )
                return;

            OleDbCommand cmd = new OleDbCommand();
            cmd.CommandText = "delete from [WedDress] where [ID]=" + id.ToString();
            cmd.CommandType = CommandType.Text;
            cmd.Connection = Program.Database;
            cmd.ExecuteNonQuery();
            cmd.Dispose();

            dt.Rows.Remove( rows[0] );
        }
开发者ID:mokacao,项目名称:backup,代码行数:28,代码来源:MainForm.cs

示例9: ExecuteSql

 public static int ExecuteSql(string SQLString)
 {
     int num2;
     using (OleDbConnection connection = new OleDbConnection(connectionString))
     {
         OleDbCommand command = new OleDbCommand(SQLString, connection);
         try
         {
             connection.Open();
             num2 = command.ExecuteNonQuery();
         }
         catch (OleDbException exception)
         {
             connection.Close();
             throw new Exception(exception.Message);
         }
         finally
         {
             if (command != null)
             {
                 command.Dispose();
             }
         }
     }
     return num2;
 }
开发者ID:SoMeTech,项目名称:SoMeRegulatory,代码行数:26,代码来源:DbHelperOleDb.cs

示例10: NewRentDlg

        public NewRentDlg( int nDressId, DateTime date )
        {
            m_nDressId = nDressId;
            m_date = date;
            m_bModify = true;

            InitializeComponent();

            OleDbCommand oc = new OleDbCommand();
            oc.CommandText = "select startdate, enddate, customer from rent where dressid=? and ? between startdate and enddate";
            oc.CommandType = CommandType.Text;
            oc.Connection = Program.Database;
            oc.Parameters.Add( "a", OleDbType.Integer ).Value = m_nDressId;
            oc.Parameters.Add( "b", OleDbType.Date ).Value = date;

            OleDbDataReader reader = oc.ExecuteReader();
            reader.Read();
            dtStartDate.Value = reader.GetDateTime( 0 );
            dtEndDate.Value = reader.GetDateTime( 1 );
            txtCustomer.Text = reader.GetString( 2 );
            reader.Dispose();
            oc.Dispose();

            this.Text = "�޸ij�����Ϣ";
        }
开发者ID:mokacao,项目名称:backup,代码行数:25,代码来源:NewRentDlg.cs

示例11: cria_DataReader_OleDb

 /// <summary>
 /// kjhkdfhgkjh
 /// </summary>
 /// <param name="sSQL"></param>
 /// <param name="conecOledb"></param>
 /// <returns> Ele retorna algo de bom</returns>
 protected static OleDbDataReader cria_DataReader_OleDb(String sSQL, OleDbConnection conecOledb)
 {
     OleDbCommand comando = new OleDbCommand(sSQL, conecOledb);
     OleDbDataReader dr = comando.ExecuteReader(CommandBehavior.CloseConnection);
     comando.Dispose();
     return dr;
 }
开发者ID:alinegonz,项目名称:Aula-de-POO3,代码行数:13,代码来源:AcessoDAL.cs

示例12: AttributesForm_Load

 private void AttributesForm_Load(object sender, EventArgs e)
 {
     try
     {
         OleDbCommand command = new OleDbCommand(srcCommand, Con);
         this.attributeSchemaXml = Convert.ToString(command.ExecuteScalar());
         command.Dispose();
         this.attributeSet = new DataSet("AttributesSet");
         if ((this.attributeSchemaXml == null) || (this.attributeSchemaXml.Length < 1))
         {
             this.attributesTable = this.attributeSet.Tables.Add("AttributesTable");
             this.attributesTable.Columns.Add("Attribute Name");
             this.attributesTable.Columns.Add("Attribute Value");
             DataRow row = this.attributesTable.NewRow();
             row["Attribute Name"] = "Enter name Of attribute";
             row["Attribute Value"] = "Enter attribute value";
             this.attributesTable.Rows.Add(row);
             this.AttributesGrid.SetDataBinding(this.attributeSet, this.attributeSet.Tables[0].TableName);
         }
         else
         {
             this.attributeSet.ReadXml(new XmlTextReader(new StringReader(this.attributeSchemaXml)));
             this.attributeSchemaXml = null;
             this.AttributesGrid.SetDataBinding(this.attributeSet, this.attributeSet.Tables[0].TableName);
         }
     }
     catch (Exception exception)
     {
         BusinessLogic.MyMessageBox(exception.Message);
     }
 }
开发者ID:krishnais,项目名称:IGain,代码行数:31,代码来源:AttributesForm.cs

示例13: ExecuteSql

 /// <summary>
 /// 执行带一个存储过程参数的的SQL语句。
 /// </summary>
 /// <param name="SQLString">SQL语句</param>
 /// <param name="content">参数内容,比如一个字段是格式复杂的文章,有特殊符号,可以通过这个方式添加</param>
 /// <returns>影响的记录数</returns>
 public static int ExecuteSql(string SQLString, string content)
 {
     using (OleDbConnection connection = new OleDbConnection(connectionString))
     {
         OleDbCommand cmd = new OleDbCommand(SQLString, connection);
         System.Data.OleDb.OleDbParameter myParameter = new System.Data.OleDb.OleDbParameter("@content", OleDbType.VarChar);
         myParameter.Value = content;
         cmd.Parameters.Add(myParameter);
         try
         {
             connection.Open();
             int rows = cmd.ExecuteNonQuery();
             return rows;
         }
         catch (System.Data.OleDb.OleDbException E)
         {
             throw new Exception(E.Message);
         }
         finally
         {
             cmd.Dispose();
             connection.Close();
         }
     }
 }
开发者ID:hoku85,项目名称:DataPie,代码行数:31,代码来源:DbHelperOleDb.cs

示例14: ExecuteNonQuery

        /// <summary>
        /// Execute  Insert,Update
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="cmdParams"></param>
        /// <returns></returns>
        public static int ExecuteNonQuery(string strSql, params OleDbParameter[] cmdParams)
        {
            OleDbConnection sqlCon = OleDbConnect();
            OleDbCommand sqlCmd = new OleDbCommand(strSql, sqlCon);
            sqlCmd.CommandType = CommandType.Text;

            //OleDbTransaction trans = sqlCon.BeginTransaction();
            //sqlCmd.Transaction = trans;
            if (cmdParams != null)
            {
                foreach (OleDbParameter parm in cmdParams)
                {
                    sqlCmd.Parameters.Add(parm);
                }
            }

            try
            {
                sqlCon.Open();
                int num = sqlCmd.ExecuteNonQuery();
                //trans.Commit();
                return num;
            }
            catch
            {
                //trans.Rollback();
                return 0;
            }
            finally
            {
                sqlCmd.Dispose();
                sqlCon.Close();
                sqlCon.Dispose();
            }
        }
开发者ID:YihuiFu,项目名称:LeTaoWX,代码行数:41,代码来源:DBHelper.cs

示例15: GetFirstnames

    public String[] GetFirstnames()
    {
        List<string> items = new List<string>();
        string strSQL = "";

        OleDbDataReader objReader = null;
        OleDbConnection objConn = null;
        OleDbCommand objCommand = null;

        strSQL = "SELECT firstname from Employees ORDER BY firstname";
        objConn = new OleDbConnection(GetconnectstringLocal());
        objConn.Open();
        objCommand = new OleDbCommand(strSQL, objConn);
        objReader = objCommand.ExecuteReader();
        while (objReader.Read())
        {

            items.Add(objReader["firstname"].ToString());

        }
        objReader.Close(); objReader.Dispose(); objReader = null;
        objCommand.Dispose(); objCommand = null;
        objConn.Close(); objConn.Dispose(); objConn = null;
        return items.ToArray();
    }
开发者ID:sathi-natarajan,项目名称:WebAppSamples_CSharp,代码行数:25,代码来源:AutoComplete.cs


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