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


C# IDbCommand.ExecuteNonQuery方法代码示例

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


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

示例1: Start

    // Use this for initialization
    void Start()
    {
        OpenDB("MakingTime.db");
       _dbcm = _dbc.CreateCommand();
      
        //Insert data 
        sqlQuery = "INSERT INTO Event (name,current_day,current_time,min_day,max_day,min_time,max_time,scheduled,creator,type) VALUES ('Date',1,1,0,3,2,3,1,'Robert','Social')";
        _dbcm.CommandText = sqlQuery;
        _dbcm.ExecuteNonQuery();

        sqlQuery = "INSERT INTO Event (name,current_day,current_time,min_day,max_day,min_time,max_time,scheduled,creator,type) VALUES ('Party',1,1,0,3,2,3,1,'Gina','Social')";
        _dbcm.CommandText = sqlQuery;
        _dbcm.ExecuteNonQuery();

        sqlQuery = "INSERT INTO Event (name,current_day,current_time,min_day,max_day,min_time,max_time,scheduled,creator,type) VALUES ('Movie',1,1,0,3,2,3,1,'Robert','Social')";
        _dbcm.CommandText = sqlQuery;
        _dbcm.ExecuteNonQuery();

        sqlQuery = "select * from Event";
        _dbcm.CommandText = sqlQuery;
        _dbr = _dbcm.ExecuteReader();

        while (_dbr.Read())
        {
            Debug.Log("****** Data: " + _dbr["name"] + "\tday: " + _dbr["current_day"] + "\tTime: " + _dbr["current_time"] + "\tMin Day: " + _dbr["min_day"]
                + "\tMax Day: " + _dbr["max_day"] + "\tMin Time: " + _dbr["min_time"] + "\tMax Time: " + _dbr["max_time"] + "\tScheduled: " + _dbr["scheduled"]
                + "\tcreator: " + _dbr["creator"] + "\ttype: " + _dbr["type"]);
        }
        _dbr.Close();
        _dbr = null;
        _dbcm.Dispose();
        _dbcm = null;
        _dbc.Close();
        _dbc = null;
    }
开发者ID:BernardoOM,项目名称:Making-Time,代码行数:36,代码来源:DBMakingTime.cs

示例2: Tablas

        public Tablas()
        {
            /*CREAMOS LAS TABLAS TELEVISOR Y COMPRADOR CON LOS CAMPOS QUE MODIFICAREMOS
             * (PRECIO,CANTIDAD,SALDO) SIENDO UNSIGNED PARA COMPROBAR QUE CUANDO ESTOS
             * CAMPOS LLEGUEN A TENER NUMEROS NEGATIVOS SE LANCE UNA EXCEPCION Y LA TRANSACCION
             * HAGA EL ROLLBACK
             *
             * */
            string conexion="Server=localhost;Database=dbprueba;" +
                             "User Id=root;Password=sistemas";

            string tabla = "CREATE TABLE IF NOT EXISTS televisor (" +
                           "id int(5) PRIMARY KEY AUTO_INCREMENT," +
                           "articulo varchar(50)," +
                           "precio decimal(10,2) unsigned," +
                           "cantidad int(5) unsigned);" +
                           "CREATE TABLE IF NOT EXISTS comprador (" +
                           "id int(5) PRIMARY KEY AUTO_INCREMENT," +
                           "saldo decimal(10,2) unsigned)";

            string insert = "INSERT INTO televisor (articulo,precio,cantidad) values('Philips',300,5)," +
                            "('MiniTv',100,5)," +
                            "('Samsung',400,5)," +
                            "('Toshiba',500,5);" +
                            "INSERT INTO comprador (saldo) values (1000)";

            MySqlConnection mySqlConnection = new MySqlConnection(conexion);
            App.Instance.DbConnection = mySqlConnection;

            dbCommand=mySqlConnection.CreateCommand();
            dbCommand.CommandText= tabla;
            dbCommand.ExecuteNonQuery();
            dbCommand.CommandText= insert;
            dbCommand.ExecuteNonQuery();
        }
开发者ID:nerea123,项目名称:ad,代码行数:35,代码来源:Tablas.cs

示例3: Criar

        internal void Criar(Sumario_Procedimento v_oSumario_Procedimento)
        {
            try
              {
              sbSQL.Length = 0;
              sbSQL.Append("INSERT INTO TBINT063(");

              sbSQL.Append("IDINT058,");
              sbSQL.Append("DSPRC,");
              sbSQL.Append("DTPRC");

              sbSQL.Append(") VALUES (");

              sbSQL.Append(":IDINT058,");
              sbSQL.Append(":DSPRC,");
              sbSQL.Append(":DTPRC");
              sbSQL.Append(")");

              sbSQL = TratarSQLParametroBanco(sbSQL.ToString());
              oCmd = ObterCommand(sbSQL.ToString());

              UtDbNet.AdicionarParametro(oCmd, TratarSQLParametroBanco("IDINT058").ToString(), Convert.ToInt32(UtSessao.Sessao["Id058"]));
              UtDbNet.AdicionarParametro(oCmd, TratarSQLParametroBanco("DSPRC").ToString(), v_oSumario_Procedimento.nome);
              UtDbNet.AdicionarParametro(oCmd, TratarSQLParametroBanco("DTPRC").ToString(), v_oSumario_Procedimento.dtprc);

              oCmd.ExecuteNonQuery();

              v_oSumario_Procedimento.Codigo = ObterNovoCodigo(oCmd, "SEQTBINT063");
              oCmd.Dispose();
              }
              catch (Exception en)
              {
              throw new Dor.Util.OperacaoInvalidaBD(en);
              }
        }
开发者ID:Workker,项目名称:SumarioDeAlta,代码行数:35,代码来源:rpSumario_Procedimento.cs

示例4: ExecuteDropStatements

 private static void ExecuteDropStatements(IEnumerable<string> stmts, IDbCommand cmd)
 {
     var list = stmts.ToList();
     Exception innerEx = null;
     for (;;)
     {
         bool didSomething = false;
         for (int i = 0; i < list.Count; i++)
         {
             try
             {
                 cmd.CommandText = list[i];
                 cmd.ExecuteNonQuery();
                 // drop was successful
                 list.RemoveAt(i);
                 i--; // Retry next entry
                 didSomething = true;
             }
             catch (SqlException ex)
             {
                 if (i == 0)
                     innerEx = ex;   // This is the exception we will later raise from this method in case we, for one reason or another, can't drop all objects.
             }
         }
         if (!didSomething)
             break;
     }
     if (list.Count > 0)
         throw new Exception(string.Format("Could not execute statement '{0}'", list[0]), innerEx);
 }
开发者ID:RichieYang,项目名称:Composable.Monolithic,代码行数:30,代码来源:DatabaseHelpers.cs

示例5: createTable

        private List<String> createTable( EntityInfo entity, IDbCommand cmd, List<String> existTables, IDictionary clsList ) {

            StringBuilder sb = new StringBuilder();
            sb.AppendFormat( "Create Table {0} (", getFullName( entity.TableName, entity ) );
            addColumn_PrimaryKey( entity, sb, clsList );

            addColumns( entity, sb );
            String str = sb.ToString().Trim().TrimEnd( new char[] { ',' } ) + " )";

            cmd.CommandText = str;
            logger.Info( "创建表:" + str );
            if (cmd.Connection == null) throw new Exception( "connection is null" );

            if (cmd.Connection.State == ConnectionState.Closed) {
                cmd.Connection.Open();
                OrmHelper.initCount++;
                LogManager.GetLogger("Class:System.Data.TableBuilderBase Method:createTable").Info("数据库连接已开启【" + OrmHelper.initCount + "】");
            }

            cmd.ExecuteNonQuery();

            existTables.Add( entity.TableName );
            logger.Info( LoggerUtil.SqlPrefix + String.Format( "create table {0} ({1})", entity.TableName, entity.FullName ) );

            return existTables;
        }
开发者ID:mfz888,项目名称:xcore,代码行数:26,代码来源:TableBuilderBase.cs

示例6: Execute

        public bool Execute(string qry)
        {
            cn = new OleDbConnection(cnString.GetConnString());
            cmd = new OleDbCommand(qry, (OleDbConnection)cn);
            try
            {
                cn.Open();
                IDbTransaction tran = cn.BeginTransaction();
                cmd.Transaction = tran;

                int affectedRows = cmd.ExecuteNonQuery();
                Console.WriteLine(affectedRows);
                if (affectedRows > 0)
                {
                    tran.Commit();
                    return true;
                }
                else
                {
                    tran.Rollback();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                cn.Close();
            }
            return false;
        }
开发者ID:hksarwar,项目名称:JobSystem,代码行数:32,代码来源:WriteCommand.cs

示例7: dbcommandparameter

 private void dbcommandparameter(IDbCommand dbcommand, string parameternombre)
 {
     IDbDataParameter dbDataParameter=dbcommand.CreateParameter();
     dbDataParameter.ParameterName ="nombre";
     dbDataParameter.Value=Value;
     dbcommand.ExecuteNonQuery();
 }
开发者ID:jonathanortizdam1993445,项目名称:ed,代码行数:7,代码来源:CategoriaView.cs

示例8: Descadastrar

		/// <summary>
		/// Exclui formato de etiqueta
		/// </summary>
		protected override void Descadastrar(IDbCommand cmd)
		{
			cmd.CommandText = "DELETE FROM etiquetaformato "
				+ "WHERE formato = " + DbTransformar(formato);

			cmd.ExecuteNonQuery();
		}
开发者ID:andrepontesmelo,项目名称:imjoias,代码行数:10,代码来源:EtiquetaFormato.cs

示例9: Criar

        internal void Criar(PerfilFuncao v_oPerfilFuncao)
        {
            try
            {
                sbSQL.Length = 0;
                sbSQL.Append("INSERT INTO TBPRO033(");

                sbSQL.Append("IDPRO016,");
                sbSQL.Append("IDPRO031");

                sbSQL.Append(") VALUES (");

                sbSQL.Append(":IDPRO016,");
                sbSQL.Append(":IDPRO031");
                sbSQL.Append(")");

                sbSQL = TratarSQLParametroBanco(sbSQL.ToString());
                oCmd = ObterCommand(sbSQL.ToString());

                UtDbNet.AdicionarParametro(oCmd, TratarSQLParametroBanco("IDPRO016").ToString(), v_oPerfilFuncao.CodigoPerfil);
                UtDbNet.AdicionarParametro(oCmd, TratarSQLParametroBanco("IDPRO031").ToString(), v_oPerfilFuncao.CodigoFuncao);

                oCmd.ExecuteNonQuery();

                v_oPerfilFuncao.Codigo = ObterNovoCodigo(oCmd, "SEQTBPRO033");
                oCmd.Dispose();
            }
            catch (Exception ex)
            {
                throw new Dor.Util.OperacaoInvalidaBD(ex);
            }
        }
开发者ID:Workker,项目名称:SumarioDeAlta,代码行数:32,代码来源:rpPerfilFuncao.cs

示例10: Descadastrar

		/// <summary>
		/// Exclui formato do banco de dados
		/// </summary>
		protected override void Descadastrar(IDbCommand cmd)
		{
			cmd.CommandText = "DELETE FROM etiquetamercadoria"
				+ " WHERE referencia = " + DbTransformar(referencia);

			cmd.ExecuteNonQuery();
		}
开发者ID:andrepontesmelo,项目名称:imjoias,代码行数:10,代码来源:EtiquetaMercadoria.cs

示例11: Criar

        internal void Criar(Uf v_oUf)
        {
            try
            {
                sbSQL.Length = 0;
                sbSQL.Append("INSERT INTO TBPRO021(");

                sbSQL.Append("CDUNDDFEDR,");
                sbSQL.Append("NMUNDDFEDR");

                sbSQL.Append(") VALUES (");

                sbSQL.Append(":CDUNDDFEDR,");
                sbSQL.Append(":NMUNDDFEDR");
                sbSQL.Append(")");

                sbSQL = TratarSQLParametroBanco(sbSQL.ToString());
                oCmd = ObterCommand(sbSQL.ToString());

                UtDbNet.AdicionarParametro(oCmd, TratarSQLParametroBanco("CDUNDDFEDR").ToString(), v_oUf.Sigla);
                UtDbNet.AdicionarParametro(oCmd, TratarSQLParametroBanco("NMUNDDFEDR").ToString(), v_oUf.Nome);

                oCmd.ExecuteNonQuery();

                v_oUf.Codigo = ObterNovoCodigo(oCmd, "SEQTBPRO021");
                oCmd.Dispose();
            }
            catch (Exception ex)
            {
                throw new Dor.Util.OperacaoInvalidaBD(ex);
            }
        }
开发者ID:Workker,项目名称:SumarioDeAlta,代码行数:32,代码来源:rpUf.cs

示例12: Execute

 public void Execute(IDbCommand command)
 {
     command.CommandText = ToString();
     whereHelper.Command = command;
     whereHelper.AppendValues();
     command.ExecuteNonQuery();
 }
开发者ID:geofflane,项目名称:zorched-migrations,代码行数:7,代码来源:SqlDeleteOperation.cs

示例13: createNewCharacter

        public UInt32 createNewCharacter(string handle, UInt32 userid, UInt32 worldId)
        {
            conn.Open();
            UInt32 charId = 0;
            //TODO: Complete with real data from a hashtable (or something to do it faster);
            //TODO: find values for uria starting place
            string sqlInsertQuery="INSERT INTO characters SET userid = '" + userid.ToString() + "', worldid='" + worldId.ToString() + "', status='0', handle = '" + handle + "', created=NOW() ";
            queryExecuter= conn.CreateCommand();
            queryExecuter.CommandText = sqlInsertQuery;
            queryExecuter.ExecuteNonQuery();

            //As i didnt find a solution for "last_insert_id" in C# we must fetch the last row by a normal query
            string sqlQuery = "SELECT charId FROM characters WHERE userId='" + userid.ToString() + "' AND worldId='" + worldId.ToString() + "' AND is_deleted='0' ORDER BY charId DESC LIMIT 1";
            queryExecuter = conn.CreateCommand();
            queryExecuter.CommandText = sqlQuery;
            dr = queryExecuter.ExecuteReader();

            while (dr.Read())
            {
                charId = (UInt32)dr.GetDecimal(0);
            }

            conn.Close();

            // Create RSI Entry
            conn.Open();
            string sqlRSIQuery = "INSERT INTO rsivalues SET charid='" + charId.ToString() + "' ";
            queryExecuter = conn.CreateCommand();
            queryExecuter.CommandText = sqlRSIQuery;
            queryExecuter.ExecuteNonQuery();

            conn.Close();

            return charId;
        }
开发者ID:hdneo,项目名称:mxo-hd,代码行数:35,代码来源:MyMarginDBAccess.cs

示例14: updateObjectType

 //        private void createObjectTypeColumn(XPClassInfo xpClassInfo, UnitOfWork unitOfWork)
 //        {
 //            unitOfWork.CreateObjectTypeRecords(xpClassInfo);
 //            var newObject = xpClassInfo.CreateNewObject(unitOfWork);
 //            unitOfWork.CommitChanges();
 //            unitOfWork.Delete(newObject);
 //            unitOfWork.CommitChanges();
 //        }
 private void updateObjectType(UnitOfWork unitOfWork, XPClassInfo xpClassInfo, XPClassInfo mergedXPClassInfo, IDbCommand command)
 {
     var propertyName = XPObject.Fields.ObjectType.PropertyName;
     command.CommandText = "UPDATE [" + getTableName(mergedXPClassInfo) + "] SET " + propertyName + "=" + unitOfWork.GetObjectType(xpClassInfo).Oid +
                           " WHERE " + propertyName + " IS NULL OR " + propertyName + "=" +unitOfWork.GetObjectType(mergedXPClassInfo).Oid;
     command.ExecuteNonQuery();
 }
开发者ID:cevious,项目名称:eXpand,代码行数:15,代码来源:XpoObjectMerger.cs

示例15: Criar

        internal void Criar(Operacao v_oOperacao)
        {
            try
              {
              sbSQL.Length = 0;
              sbSQL.Append("INSERT INTO TBPRO020(");

              sbSQL.Append("DSAPLDOPRC,");
              sbSQL.Append("NMOPRC");

              sbSQL.Append(") VALUES (");

              sbSQL.Append(":DSAPLDOPRC,");
              sbSQL.Append(":NMOPRC");
              sbSQL.Append(")");

              sbSQL = TratarSQLParametroBanco(sbSQL.ToString());
              oCmd = ObterCommand(sbSQL.ToString());

              UtDbNet.AdicionarParametro(oCmd, TratarSQLParametroBanco("DSAPLDOPRC").ToString(), v_oOperacao.Apelido);
              UtDbNet.AdicionarParametro(oCmd, TratarSQLParametroBanco("NMOPRC").ToString(), v_oOperacao.Nome);

              oCmd.ExecuteNonQuery();

              v_oOperacao.Codigo = ObterNovoCodigo(oCmd, "SEQTBPRO020");
              oCmd.Dispose();
              }
              catch (Exception ex)
              {
              throw new Dor.Util.OperacaoInvalidaBD(ex);
              }
        }
开发者ID:Workker,项目名称:SumarioDeAlta,代码行数:32,代码来源:rpOperacao.cs


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