Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将OracleLob作为参数传递给函数_C#_.net_Oracle_Ado.net_Blob - Fatal编程技术网

C# 将OracleLob作为参数传递给函数

C# 将OracleLob作为参数传递给函数,c#,.net,oracle,ado.net,blob,C#,.net,Oracle,Ado.net,Blob,我想完成一件类似的事情: try { openConnection(); OracleCommand cmd = new OracleCommand("SELECT CUSTOMER_ID, IMAGE_BLOB FROM CUSTOMER_IMAGE WHERE CUSTOMER_ID IN (3026)", conn); string pubID = ""; OracleDataReader reader = cmd.ExecuteReader(Command

我想完成一件类似的事情:

try
{
    openConnection();
    OracleCommand cmd = new OracleCommand("SELECT CUSTOMER_ID, IMAGE_BLOB FROM CUSTOMER_IMAGE WHERE CUSTOMER_ID IN (3026)", conn);
    string pubID = "";
    OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess);

    //create the report object
    MemoryStream memStream;
    DataSet ds = new DataSet();
    DataTable ImageTable = new DataTable();
    BinaryReader binReader;
    DataRow dr;

    byte[] byteArrName;
    OracleLob blob;

    while (reader.Read())
    {
        pubID = reader.GetValue(0).ToString();

        // Obtain a LOB
        blob = reader.GetOracleLob(1);

        // Create a byte array of the size of the Blob obtained
        byteArrName = new byte[blob.Length];

        // Read blob data into byte array
        int i = blob.Read(byteArrName, 0, System.Convert.ToInt32(blob.Length));

        //Copied the contents of byte array to stream
        memStream = new MemoryStream(byteArrName);

        //Create a column of type byte[]
        ImageTable.Columns.Add(new DataColumn("id", typeof(string)));
        ImageTable.Columns.Add(new DataColumn("image", typeof(System.Byte[])));

        //Reading the stream which has the blob data
        binReader = new BinaryReader(memStream);
        dr = ImageTable.NewRow();

        dr["id"] = pubID;
        //ReadBytes method to add a byte array of the image stream.
        dr["image"] = binReader.ReadBytes((int)binReader.BaseStream.Length);
        ImageTable.Rows.Add(dr);

        memStream.Close();
        binReader.Close();
    }

    ds.Tables.Add(ImageTable);

    //Creating a temporary dataset which hold the image
    ds.WriteXmlSchema(@Directory.GetCurrentDirectory() + "\\temp.xsd");

    reader.Close();
    conn.Close();
}
现在,我将在Crystal报告中填充temp.xsd,以便动态显示图像。这只是我从头开始编写的一个示例代码,但是为了适合我的场景,我需要获取已经在
dtAcctSigner.Rows[0][“image\u BLOB”],
中的图像,所以我想知道是否有任何方法可以像在上面的代码中一样获取此BLOB

OracleDataReader.GetOracleLob();
为此,我需要将datatable的一列(OracleLob类型)作为参数传递给如下函数:

Update(dtAcctSigner.Rows[0]["IMAGE_BLOB"]);
其功能如下:

public void Update(OracleLob a)
{ 
// I want to do take the OracleLob and make into a memorystream and put it into temp.xsd here
}
但我有一个错误:

cannot convert 'object' to 'OracleLob'
请让我知道我做错了什么

using(reader)
{
      //Obtain the first row of data.
      reader.Read();
      //Obtain the LOBs (all 3 varieties).
      OracleLob BLOB = reader.GetOracleLob(1);
      ...

      //Example - Reading binary data (in chunks).
      byte[] buffer = new byte[4096];
      while((actual = BLOB.Read(buffer, 0, buffer.Length)) >0)
         Console.WriteLine(BLOB.LobType + 
            ".Read(" + buffer + ", " + buffer.Length + ") => " + actual);

      ...
}
我个人会以这种方式创建列并将其添加到数据表中,但这取决于您是否以这种方式尝试,或者您知道可以使用的其他方式

DataTable table = new DataTable("ImageTable"); //Create a new DataTable instance.

DataColumn column0 = new DataColumn("id"); //Create the column.
column.DataType = System.Type.GetType("System.String"); //Type string 

DataColumn column1 = new DataColumn("image"); //Create the column.
column.DataType = System.Type.GetType("System.Byte[]"); //Type byte[] to store image bytes.
column.AllowDBNull = true;
column.Caption = "My Image";

table.Columns.Add(column0); //Add the column to the table.
table.Columns.Add(column1); //Add the column to the table.

Then, add a new row to this table and set the value of the MyImage column.

DataRow row = table.NewRow();
row["MyImage"] = <Image byte array>;
tables.Rows.Add(row);
DataTable=新的DataTable(“ImageTable”)//创建一个新的DataTable实例。
DataColumn column0=新的DataColumn(“id”)//创建列。
column.DataType=System.Type.GetType(“System.String”)//类型字符串
DataColumn column1=新的DataColumn(“图像”)//创建列。
column.DataType=System.Type.GetType(“System.Byte[]”)//键入byte[]以存储图像字节。
column.AllowDBNull=true;
column.Caption=“我的图像”;
表.Columns.Add(第0列)//将列添加到表中。
表.列.添加(第1列)//将列添加到表中。
然后,在此表中添加新行并设置MyImage列的值。
DataRow行=table.NewRow();
行[“MyImage”]=;
tables.Rows.Add(row);

然后你需要澄清你的问题。。也不要发布空的代码方法。。如果我们要帮助您,您必须更清楚/具体地了解您面临的问题。。这有点令人困惑/难以理解您试图实现的目标。请显示有关如何传递更新的完整代码(dtAcctSigner.Rows[iCount1][“SIGNATURE\u BLOB]”);以及声明datatableOk谢谢。将编辑代码。当情况如下时,大多数人会投反对票1。没有显示足够的个人研究2。本质上非常抽象。这不是一个真正的问题。。etc@DJKRAZE:我编辑了这个问题,请用reader.Read()查看一下,这个代码可以作为示例应用程序使用。但是在主代码中,我没有OracleDataReader,相反,我有DataTable,所以,我是否可以将该列(IMAGE_BLOB)转换为OracleLob?此代码帮助我了解块。但是我把它转换成一个内存流,只是因为我应该在运行时使图像在CrystalReports中可写。。我将添加另一个示例,说明如何创建DataTable并分配上面答案下面的列。我将把它放入内存流,并将其写入硬盘中的临时xml模式,以便将其填充到CrystalReports中。另外,对于使用reader.GetOracleLob,我没有使用OracleDataReader,而是在Datatable中使用了这个BLOB对象。因此,我需要知道如何在没有OracleDataReader的情况下将datatable中的列转换为oraclelob。