将大型CLOB对象转换为.NET字符串以放入DataGridView单元格 [英] Converting a large CLOB object to .NET string to put into a DataGridView cell
问题描述
我已经用C#创建了一个Windows Forms GUI,可以在DataGridView中显示表格数据(针对Oracle Server DB的SQL查询结果).字段之一是XML(可能很大),它存储为CLOB(如果我是对的,则为Character Large OBject).当然,用户不会直接查看该单元格,而是会双击该单元格以查看打印精美的文件.问题是我需要将文件(是CLOB)转换为.NET字符串,否则它将生成异常.作为一种解决方法,我已尝试使用Oracle to_char过程,但该过程限制为4000个字符.因此,我将文件的子字符串像这样:
I have created a Windows Forms GUI in C# that can display tabular data (results of an SQL query against an Oracle Server DB) in a DataGridView. One of the field is an XML, potentially quite large, stored as a CLOB (Character Large OBject if I'm right). Of course, the user will not directly look at the cell, he will rather double-click the cell to see the file pretty-printed. The problem is that I need to convert the file (which is a CLOB) to a .NET String otherwise it generates an exception. I have tried, as a workaround, to use the Oracle to_char procedure, but it is limited to 4000 characters. So I take a substring of the file like this:
select to_char(dbms_lob.substr(column_name, 4000, 1 ))
问题是,如果文件超过4000个字符,它不会显示整个文件.我该如何规避此限制?
The problem is, it doesn't display the whole file if it contains more than 4000 characters. How could I circumvent this limitation?
推荐答案
我使用了简单的方法:
if (reader.IsDBNull(i))
{
cellValue = "NULL";
}
else
{
OracleLob clob = reader.GetOracleLob(i);
cellValue = (string) clob.Value;
}
这篇关于将大型CLOB对象转换为.NET字符串以放入DataGridView单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!