当前位置:编程学习 > C#/ASP.NET >>

c#中clob转换为string

怎么将clob转换为 string --------------------编程问答-------------------- 参考代码:
using System.Data.OracleClient;
using System.IO;
using System.Text;

        int actual = 0;

        //this.FreeTextBox1.Text = "<FONT color=#ffc0cb>this is as test</FONT>";
        OracleConnection conn = new OracleConnection("Data Source=INFOPLAT;User ID=infomanager;Password=admin;");
        OracleCommand cmd = new OracleCommand();

        cmd.Connection = conn;
        String strSql = "SELECT 相关链接 FROM xxtable where SN='88'";

        cmd.CommandText = strSql;

        cmd.CommandType = CommandType.Text;

        try
        {
            conn.Open();

            OracleDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {

                OracleLob myOracleClob = reader.GetOracleLob(0);

                StreamReader streamreader = new StreamReader(myOracleClob, Encoding.Unicode);
                char[] cbuffer = new char[100];
                while ((actual = streamreader.Read(cbuffer, 0, cbuffer.Length)) > 0)
                {
                    String test = new string(cbuffer, 0, actual);
                    FreeTextBox1.Text = test;
                }
               


                break;
            }

        }
        catch (Exception ex)
        {

        }
        finally
        {
            // 释放占有资源
            conn.Close();
        }

c#操作clob  
using System;

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= "Data Source=" + OracleIP + ";User ID=" + OracleUserName + ";PASSWORD=" + OraclePassword + ";";    
            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[] new = System.Text.Encoding.Unicode.GetBytes(str); 
                sqlCommandOracle=newSystem.Data.OracleClient.OracleCommand(SQLStatement,connOracle);                             
                rstOracle = sqlCommandOracle.ExecuteReader(); 
                rstOracle.Read();                             
                txn = connOracle.BeginTransaction();                 
                clob = rstOracle.GetOracleLob(0);                      
                clob.Write(new, 0, new.Length);                        
                
                txn.Commit();                     
            }                             
        }          
    }
     public void CloseDatabase()         
    {

         connOracle.Close(); 
         connOracle.Dispose();       
     }           


private void btnSave_Click(object sender, System.EventArgs e)
{
clsOracle db=new clsOracle();  

// example for primary key 
string field_id = "1";   
// insert 2 characters for addresing 
string field_temp = "XX";

string sql = "Insert into table_nm s('" + field_id + "', '" + field_temp + "')"; 
db.InsertRecord(sql);

sql="select news_text from table_nm +
"WHERE field_nm'" + field_id + "' FOR UPDATE";
    
db.InsertCLOB(sql, txtCLOBData.Text.ToString()); 
db.CloseDatabase();
}
 

--------------------编程问答-------------------- 楼上这一陀,是撒?
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,