public int Execute(string sql, Hashtable ht = null)
{
using (OracleConnection conn = new OracleConnection(this.connStr))
{
try
{
if (ht == null || ht.Count == 0)
{
if (conn.State != ConnectionState.Connecting)
conn.Open();
OracleCommand cmd = new OracleCommand(sql, conn);
int n = cmd.ExecuteNonQuery();
cmd.Connection = null;
return n;
}
else
{
if (conn.State != ConnectionState.Connecting)
conn.Open();
OracleCommand cmd = new OracleCommand(sql, conn);
foreach (DictionaryEntry de in ht)
{
cmd.Parameters.Add(new OracleParameter(de.Key.ToString(), de.Value.ToString()));
}
int n = cmd.ExecuteNonQuery();
cmd.Connection = null;
return n;
}
}
catch (Exception e)
{
throw e;
}
}
}
1、sql语句用到的参数个数和ht中的对象个数必须一致,否则执行报错;