ORACLE中LONG类型字段的存取

时间:2011-04-07 14:41:31  来源:第二电脑网上收集  作者:

  第二电脑网导读:E TEST (    AGREEMENT_ID      CHAR(3) NOT NULL,    AGREEMENT_CONTENT LONG        NULL)插入数据:    protected void Button1_Click(object sender, EventArgs e)    {  &n...
  正文:

ORACLE中存取4000字节以上大文本类型可以用此数据类型,其在C#中的读写方法如下:

注意需要引用 System.Data.OracleClient
然后添加命名空间:using System.Data.OracleClient

ORALCE建库脚本:

CREATE TABLE TEST
(
    AGREEMENT_ID      CHAR(3) NOT NULL,
    AGREEMENT_CONTENT LONG        NULL
)
插入数据:

    protected void Button1_Click(object sender, EventArgs e)
    {
        OracleConnection conn = new OracleConnection(@"Password=XXXXXX;User ID=hk;Data Source=wealth;Persist Security Info=True");
        conn.Open();
        OracleCommand cmd = new OracleCommand("Select * From TEST", conn);
        string sql = "Insert Into TEST (AGREEMENT_ID, AGREEMENT_CONTENT)   Values(:P_ID,   :P_Value)";
        cmd.CommandText = sql;
        cmd.Parameters.Add("P_ID", this.TextBox2.Text);
        cmd.Parameters.Add("P_Value", this.TextBox1.Text);
        cmd.ExecuteNonQuery();
        conn.Close();
    }
读取数据:
    protected void Button2_Click(object sender, EventArgs e)
    {
        OracleConnection conn = new OracleConnection(@"Password=XXXXXX;User ID=hk;Data Source=wealth;Persist Security Info=True");
        conn.Open();
        string sql = "Select   *   From   TEST where AGREEMENT_ID = :P_ID";
        OracleDataAdapter da = new OracleDataAdapter(sql, conn);
        da.SelectCommand.Parameters.Add("P_ID", this.TextBox2.Text);
        DataSet ds = new DataSet();

        da.Fill(ds);
        this.TextBox1.Text = ds.Tables[0].Rows.Count.ToString();
        this.TextBox1.Text = ds.Tables[0].Rows[0]["AGREEMENT_CONTENT"].ToString();
        conn.Close();
    }

"ORACLE中LONG类型字段的存取"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Database/Oracle/2009-01-07/8530.html


关于《ORACLE中LONG类型字段的存取》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td