以下的文章主要是對Oracle存取LONG類型字段的方案的介紹,我們都知道在Oracle中存取超過4000字節的相關的大文本類型都可以用此相關的數據類型,其在C#中的讀寫方法如下:注意需要引用 System.Data.OracleClIEnt。
然後添加命名空間:using System.Data.OracleClIEnt
Oracle建庫腳本:
- 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();
- }