本文整理汇总了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;
}
示例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();
}
示例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);
}
}
示例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);
}
示例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;
}
示例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;
}
示例7: dbcommandparameter
private void dbcommandparameter(IDbCommand dbcommand, string parameternombre)
{
IDbDataParameter dbDataParameter=dbcommand.CreateParameter();
dbDataParameter.ParameterName ="nombre";
dbDataParameter.Value=Value;
dbcommand.ExecuteNonQuery();
}
示例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();
}
示例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);
}
}
示例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();
}
示例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);
}
}
示例12: Execute
public void Execute(IDbCommand command)
{
command.CommandText = ToString();
whereHelper.Command = command;
whereHelper.AppendValues();
command.ExecuteNonQuery();
}
示例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;
}
示例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();
}
示例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);
}
}