日期:2009-10-09  浏览次数:20422 次

尝试的情况是,提供一个TEXT 框,让用户输入,允许输入非常多的值,保存到Oracle 数据库中。 为了能够大量数据保存,因此,对字段类型设置为 blob 型 。

网络上的类似帮助太复杂了,发现如果只是文件内的操作,还是比较简单的。
思路:
1。先将text 文本转变成2进制
byte[] ddd;
ddd = System.Text.Encoding.Unicode.GetBytes(this.textBox1.Text);

2。再将该2进制存入数据库中,发现这种对数据库的访问方法可行。
cmd.Parameters.Add 。。。
cmd.ExecuteNonQuery();

表结构如下:
create table XLUTEST
(
HHHH BLOB,
GGGG VARCHAR2(10)
)
tablespace SYSTEM
pctfree 10
pctused 40
initrans 1
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
)


c# 全部WINFORM 代码如下 :
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using System.IO;

namespace blob
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.textBox1.Location = new System.Drawing.Point(40, 48);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(576, 272);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "textBox1";
//
// button1
//
this.button1.Location = new System.Drawing.Point(240, 336);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "SAVE";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(408, 344);
this.button2.Name = "button2";
this.button2.TabIndex = 2;
this.button2.Text = "READ";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(88, 336);
this.button3.Name = "button3";
this.button3.TabIndex = 3;
this.button3.Text = "UPDATE";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Form1
//
t