#region 新的数据新增和修改方法
/// <summary>
/// 添加信息
/// </summary>
/// <returns></returns>
public static bool AddInfo(string name, string pid, string content)
{
OracleConnection conn = new OracleConnection(connectionstring);
OracleCommand cmd = conn.CreateCommand();
OracleTransaction objTran = null;
try
{
conn.Open();
objTran = conn.BeginTransaction();
cmd.Transaction = objTran;
//创建临时clob变量
cmd.CommandText = "DECLARE dpClob CLOB; BEGIN DBMS_LOB.CREATETEMPORARY(dpClob, False, 0); :tmpClob := dpClob; END;";
OracleParameter op1 = new OracleParameter("tmpClob", OracleType.Clob);
op1.Direction = ParameterDirection.Output;
cmd.Parameters.Add(op1);
cmd.ExecuteNonQuery();
OracleLob tempLob;
tempLob = (OracleLob)cmd.Parameters[0].Value;
tempLob.BeginBatch(OracleLobOpenMode.ReadWrite);
byte[] buffer = Encoding.Unicode.GetBytes(content);
tempLob.Write(buffer, 0, buffer.Length);//将值写入临时变量中
tempLob.EndBatch();
cmd.Parameters.Clear();
cmd.CommandText = "insert into t_yingjiinfo (id,nodename,pid,content) values ( seq_t_yingjiinfo.nextval,‘" + name + "‘, " + pid + ",:contentText)";
cmd.CommandType = CommandType.Text;
OracleParameter op2 = new OracleParameter("contentText", OracleType.Clob);
op2.Value = tempLob;
cmd.Parameters.Add(op2);
cmd.ExecuteNonQuery();
objTran.Commit();
cmd.Parameters.Clear();
return true;
}
catch
{
objTran.Rollback();
return false;
}
finally
{
objTran.Dispose();
cmd.Dispose();
conn.Close();
conn.Dispose();
}
}
/// <summary>
/// 更新数据 更新一般修理二维码字段 暂时只有陕西省
/// </summary>
/// <returns></returns>
public static bool UpdateInfo(string bianhao, string content)
{
OracleConnection conn = new OracleConnection(connectionstring);
OracleCommand cmd = conn.CreateCommand();
OracleTransaction objTran = null;
try
{
conn.Open();
objTran = conn.BeginTransaction();
cmd.Transaction = objTran;
cmd.CommandText = "DECLARE dpClob CLOB; BEGIN DBMS_LOB.CREATETEMPORARY(dpClob, False, 0); :tmpClob := dpClob; END;";
OracleParameter op1 = new OracleParameter("tmpClob", OracleType.Clob);
op1.Direction = ParameterDirection.Output;
cmd.Parameters.Add(op1);
cmd.ExecuteNonQuery();
OracleLob tempLob;
tempLob = (OracleLob)cmd.Parameters[0].Value;
tempLob.BeginBatch(OracleLobOpenMode.ReadWrite);
byte[] buffer = Encoding.Unicode.GetBytes(content);
tempLob.Write(buffer, 0, buffer.Length);
tempLob.EndBatch();
cmd.Parameters.Clear();
cmd.CommandText = "update wh_qrcode set qrcode = :contentText where bianhao = ‘" + bianhao + "‘";
cmd.CommandType = CommandType.Text;
OracleParameter op2 = new OracleParameter("contentText", OracleType.Clob);
op2.Value = tempLob;
cmd.Parameters.Add(op2);
cmd.ExecuteNonQuery();
objTran.Commit();
cmd.Parameters.Clear();
return true;
}
catch
{
objTran.Rollback();
return false;
}
finally
{
objTran.Dispose();
cmd.Dispose();
conn.Close();
conn.Dispose();
}
}
#endregion
原文地址:https://www.cnblogs.com/sukhoi/p/9059642.html