you are probably using the wrong type, see the part about OleDbCommand inhttp://support.microsoft.com/default.aspx?scid=kb;EN-US;Q316887

解决方案 »

  1.   

    to saucer(思归, MS .NET MVP) 有没有c#的例子?
      

  2.   

    要把sr转成byte[]byte[] bytes = new byte[(int)sr.Length];
    sr.Read(bytes, 0, bytes.Length);
    sr.Close();//
    myCommand.Parameters["@stream"].Value=bytes;
      

  3.   

    to panyee(快乐王子) 
    好像没有StreamReader.Length的方法吧?
      

  4.   

    用FileStream fs = new FileStream("c:\\1.dat", FileMode.Open, FileAccess.Read);
      

  5.   

    用FileSteam fs = new FileStream("c:\\1.dat", FileMode.Open, FileAccess.Read);fs.Length;
      

  6.   

    to  panyee(快乐王子) 谢了!
    向oracle添加成功了,但从oracle读出来的时候出错:
    未指定的错误发生了一个 Oracle 错误,但无法从 Oracle 中检索错误信息。数据类型不被支持。
    表是test(id number ,stream blob)
    写入stream的代码:
                               FileStream fs = File.OpenRead("c:\\1.txt");
    string   strConnectDb;
    byte[] bytes = new byte[(int)fs.Length];
    fs.Read(bytes, 0, bytes.Length);
    fs.Close();
    System.Data.OleDb.OleDbConnection  oleConnect = null;
    strConnectDb = "Provider=MSDAORA;Password=manager;User ID=system;Data Source=zengting";
    oleConnect=new OleDbConnection(strConnectDb);
    oleConnect.Open();
    string str="insert into test values(stream.nextval,?)";
    OleDbCommand myCommand=new OleDbCommand(str,oleConnect);
    myCommand.Parameters.Add(new OleDbParameter("@blob",OleDbType.Binary,bytes.Length,"blob"));
    myCommand.Parameters["@blob"].Value=bytes;
    myCommand.ExecuteNonQuery();
    读出stream的代码:
                               string   strConnectDb;
    System.Data.OleDb.OleDbConnection  oleConnect = null;
    strConnectDb  = "Provider=MSDAORA;Password=manager;User ID=system;Data Source=zen";
    oleConnect=new OleDbConnection(strConnectDb);
    oleConnect.Open();
    string str="select stream from test where ID=2";
    OleDbCommand myCommand=new OleDbCommand (str,oleConnect);
    OleDbDataReader myReader=myCommand.ExecuteReader();//出错
    请问,怎样读出来写到一个新的文件里?
      

  7.   

    读的时候这样就出错?不太可能吧?
    如果读出正确的话,用下列语句保存byte[] bytes = (byte[])myReader["stream"];然后FileStream fs = new FileStream("c:\\456.txt", 
                       FileMode.OpenOrCreate, FileAccess.Write);
    fs.Write(bytes, 0, bytes.Length);
    fs.Flush();
    fs.Close();
      

  8.   

    你的代码中:
    test(id number ,stream blob)
    myCommand.Parameters.Add(new OleDbParameter("@blob",OleDbType.Binary,bytes.Length,"blob"));你的参数应该要写成
    ("@blob",OleDbType.Binary,bytes.Length,"stream"));
      

  9.   

    to panyee(快乐王子) ( ) 
    OleDbDataReader myReader=myCommand.ExecuteReader();
    这句已经出错了。出错信息:未指定的错误发生了一个 Oracle 错误,但无法从 Oracle 中检索错误信息。数据类型不被支持。
      

  10.   

    我把select语句改成:select id from test where ID=2
    OleDbDataReader myReader=myCommand.ExecuteReader();就不出错了,这说明是转换的问题。
    我用byte[] bytes=(byte[])myCommand.ExecuteReader();编译不过,提示不能转换成byte[]
      

  11.   

    如果直接在sql plus里执行是什么结果?
      

  12.   

    可以啊!我用toad,select语句没有问题
    select stream from test;
    STREAM     
    -----------
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    <BLOB>     
    32 rows selected
     
     
      

  13.   

    但不知道stream字段里是否有数据?
      

  14.   

    看来这个字段非得请Oracle Provider for .Net出马了,OleDb无法胜任
      

  15.   

    oledb不能读oracle的blob字段?
    还有其他方法吗?Oracle Provider for .Net我没有用过,行吗?
      

  16.   

    Oracle.net组件里的例子   ///////////////////////////////////////////////////////////////
       // ReadLobExample
       //
       ///////////////////////////////////////////////////////////////
       public static void ReadLobExample(OracleCommand cmd)
       {
          int actual = 0;      //Select some data.
          //   Table Schema:
          //      "CREATE TABLE tablewithlobs (a int, b BLOB, c CLOB, d NCLOB)";
          //      "INSERT INTO tablewithlobs values (1, 'AA', 'AAA', N'AAAA')";
          cmd.CommandText   = "SELECT * FROM tablewithlobs";
          OracleDataReader reader = cmd.ExecuteReader();
          using(reader)
          {
             //Obtain the first row of data.
             reader.Read();
             
             //Obtain the LOBs (all 3 varieties).
             OracleLob BLOB   = reader.GetOracleLob(1/*0:based ordinal*/);
             OracleLob CLOB  = reader.GetOracleLob(2/*0:based ordinal*/);
             OracleLob NCLOB = reader.GetOracleLob(3/*0:based ordinal*/);         //Example - Reading binary data (in chunks).
             byte[] buffer = new byte[100];
             while((actual = blob.Read(buffer, 0/*buffer offset*/, buffer.Length/*count*/)) >0)
                Console.WriteLine(blob.LobType + ".Read(" + buffer + ", " + buffer.Length + ") => " + actual);         //Example - Reading CLOB/NCLOB data (in chunks).
             //Note: You can read character data as raw Unicode bytes (using OracleLob.Read as in the above example).
             //However, because the OracleLob object inherits directly from the .Net stream object, 
             //all the existing classes that manipluate streams can also be used. For example, the 
             //.Net StreamReader makes converting the raw bytes into actual characters easier.
             StreamReader streamreader = new StreamReader(clob, Encoding.Unicode);
             char[] cbuffer = new char[100];
             while((actual = streamreader.Read(cbuffer, 0/*buffer offset*/, cbuffer.Length/*count*/)) >0)
                Console.WriteLine(CLOB.LobType + ".Read(" + new string(cbuffer, 0, actual) + ", " + cbuffer.Length + ") => " + actual);         //Example - Reading data (all at once).
             //You could use StreamReader.ReadToEnd to obtain all the string data,or simply
             //call OracleLob.Value to obtain a contiguous allocation of all the data.
             Console.WriteLine(NCLOB.LobType + ".Value => " + NCLOB.Value);
          }
       }
      

  17.   

    在.NET 1.0 里System.Data.OracleClient不支持远程访问,建议你用LongRaw类型
      

  18.   

    i come!useing:
    system.io.filestream f = new filestream(filepath,filmode.open)
    if
    {
      bye[] bt = new byte[f.length];
      int d = f.length;
      f.read(bt,0,d);
      oracleConnection conn = new oracleconnection("string");
      conn.open()
      oraclecommand commd = new oraclecommand;
      commd.connection = conn;
      sql = "insert tba value(:O_blob)";
      system.data.oracleclient.oracleparameter op = new oracleparameter();
      op.oracletype = oracletype.blob;
      op.parametername = ":o_blob";
      op.value = bt;
      commd.parameters.add(op);
      commd.exectenoquery();
      conn.clsoe();
    }
    need:
    system.data.oracleclient.dll
     
    this in .net framework1.1