C#.net Oracle 插入 clob 数据问题
向大家请教一个问题:C#.net 如何在oracle数据库中插入与读取大文本,数据类型为clob
--------------------编程问答-------------------- 没用过。帮顶 --------------------编程问答-------------------- 呵呵,好像上次遇到过,我记得我当时先插入一个对象,然后更新这个对象就可以了! --------------------编程问答-------------------- sqlCommand1=new OracleCommand(sql,conn1);
OracleParameter param1=new OracleParameter ( "img_data", OracleType.Clob);
param1.Value = imgbin;
sqlCommand1.Parameters.Add( param1 ); --------------------编程问答-------------------- 问题已解决,谢谢大家
先插入,后更新,这是从网上搜到的源码
namespace InsertingCLOB
{
public class clsOracle
{
private System.Data.OracleClient.OracleConnection connOracle;
private System.Data.OracleClient.OracleDataReader rstOracle;
private System.Data.OracleClient.OracleCommand sqlCommandOracle;
private System.Data.OracleClient.OracleTransaction txn;
private System.Data.OracleClient.OracleLob clob;
public clsOracle()
{
string p_conn_db = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
connOracle = new System.Data.OracleClient.OracleConnection(p_conn_db);
connOracle.Open();
}
public void InsertRecord(string SQLStatement)
{
if (SQLStatement.Length>0)
{
if(connOracle.State.ToString().Equals("Open"))
{
sqlCommandOracle = new System.Data.OracleClient.OracleCommand(SQLStatement,connOracle);
sqlCommandOracle.ExecuteScalar();
}
}
}
public void InsertCLOB(string SQLStatement, string str)
{
if (SQLStatement.Length > 0)
{
if (connOracle.State.ToString().Equals("Open"))
{
byte[] newvalue = System.Text.Encoding.Unicode.GetBytes(str);
sqlCommandOracle = new System.Data.OracleClient.OracleCommand(SQLStatement, connOracle);
rstOracle = sqlCommandOracle.ExecuteReader();
rstOracle.Read();
txn = connOracle.BeginTransaction();
clob = rstOracle.GetOracleLob(0);
clob.Write(newvalue, 0, newvalue.Length);
txn.Commit();
}
}
}
public void CloseDatabase()
{
connOracle.Close();
connOracle.Dispose();
}
}
}
--------------------编程问答-------------------- 用参数解决问题,发一个例子给你看哈。
1.//利用传参数
2. OracleConnection Con = new System.Data.OracleClient.OracleConnection(strCon);
3. Con.Open();
4. //自己用时,替换自己的sql语句
5. string cmdText="insert into xmgl_wd(pk_wdbh,wdmc,lbbh,wdnr,wdfjdz,wdsj,istj) values (XMGL_WD_SEQ.Nextval,'"+wdmc+"','"+lbbh+"',:pb,'"+wdfjdz+"',"+str_add_wdsj+",'"+istj+"')";
6. OracleCommand cmd = new OracleCommand(cmdText,Con);
7. OracleParameter op = new OracleParameter("pb",OracleType.Clob);
8. op.Value = wdnr;
9. cmd.Parameters.Add(op);
10. cmd.ExecuteNonQuery();
11. Con.Close();
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/anotherlilei/archive/2010/04/01/5440706.aspx --------------------编程问答--------------------
大文本,我建議你用long類型,方法用5樓的
用参数解决问题,发一个例子给你看哈。
1.//利用传参数
2. OracleConnection Con = new System.Data.OracleClient.OracleConnection(strCon);
3. Con.Open();
4. //自己用时,替换自己的sql语句
5. string cmdText="insert into xmgl_wd(pk_wdbh,wdmc,lbbh,wdnr,wdfjdz,wdsj,istj) values (XMGL_WD_SEQ.Nextval,'"+wdmc+"','"+lbbh+"',:pb,'"+wdfjdz+"',"+str_add_wdsj+",'"+istj+"')";
6. OracleCommand cmd = new OracleCommand(cmdText,Con);
7. OracleParameter op = new OracleParameter("pb",OracleType.long);
8. op.Value = wdnr;
9. cmd.Parameters.Add(op);
10. cmd.ExecuteNonQuery();
11. Con.Close();
补充:.NET技术 , ASP.NET