P
phil
I'm having the same problem. Basically, what I need to
know is - Can I move more than 4000 characters from a
TextBox in a Web Form to a string? If so, some code that
illustrates how to do this would be appreciated.
know is - Can I move more than 4000 characters from a
TextBox in a Web Form to a string? If so, some code that
illustrates how to do this would be appreciated.
-----Original Message-----
Hi,
I'm trying to send >4000 text data from a TextBox to a
clob column of an Oracle table.
code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Threading;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
namespace clobdata
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected
System.Web.UI.WebControls.TextBox TextBox1;
protected
System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button
Button2;
protected System.Web.UI.WebControls.Label
Label1;
protected System.Web.UI.WebControls.Label
Label2;
protected System.Web.UI.WebControls.Button
Button1;
private void Page_Load(object sender,
System.EventArgs e)
{
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required
by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support -
do not modify
/// the contents of this method with the
code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new
System.EventHandler(this.Button1_Click);
this.Button2.Click += new
System.EventHandler(this.Button2_Click);
this.Load += new
System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender,
System.EventArgs e)
{
String s = TextBox1.Text;
OracleConnection con = Connect
("User Id=scott;Password=tiger;Data Source=Oracle");
StringBuilder blr;
OracleCommand cmd = new
OracleCommand("", con);
blr = new StringBuilder();
blr.Append("DROP TABLE clobtest");
cmd.CommandText = blr.ToString();
try
{
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
//Console.WriteLine
("Warning: {0}", ex.Message);
}
blr = new StringBuilder();
blr.Append("CREATE TABLE clobtest
(col1 NUMBER(4) PRIMARY KEY,");
blr.Append("clobcol CLOB, sound
BLOB)");
cmd.CommandText = blr.ToString();
try
{
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine("Error:
{0}", ex.Message);
}
blr = new StringBuilder();
blr.Append("INSERT INTO clobtest
values(");
blr.Append("1,");
blr.Append("'" + s + "',");
blr.Append("'65667777')");
cmd.CommandText = blr.ToString();
try
{
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine("Error:
{0}", ex.Message);
}
StringBuilder sql = new
StringBuilder();
sql.Append("create or replace
procedure Selectclobcol ( ");
sql.Append("clob_data OUT CLOB)
as ");
sql.Append("begin ");
sql.Append(" select clobcol into
clob_data from clobtest where col1 = 1; ");
sql.Append("end Selectclobcol;");
cmd.CommandText = sql.ToString();
try
{
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine("Error:
{0}", ex.Message);
}
// Set the command
OracleCommand cmd2 = new
OracleCommand("", con);
cmd2.CommandText = "Selectclobcol";
cmd2.CommandType =
CommandType.StoredProcedure;
// Bind the OraLob Object
OracleParameter param =
cmd2.Parameters.Add("clobdata", OracleDbType.Clob);
param.Direction =
ParameterDirection.Output;
// Execute command
try
{
cmd2.ExecuteNonQuery();
string lob_data = (string)
((OracleClob)(cmd2.Parameters[0].Value)).Value;
}
catch (Exception ex)
{
Console.WriteLine
(ex.Message);
}
finally
{
// Dispose OracleCommand
object
cmd2.Dispose();
// Close and Dispose
OracleConnection object
con.Close();
con.Dispose();
}
}
public static OracleConnection Connect
(string connectStr)
{
OracleConnection con = new
OracleConnection(connectStr);
try
{
con.Open();
}
catch (Exception e)
{
Console.WriteLine("Error:
{0}", e.Message);
}
return con;
}
private void Button2_Click(object sender,
System.EventArgs e)
{
OracleConnection con = Connect
("User Id=scott;Password=tiger;Data Source=dell2");
OracleCommand cmd = new
OracleCommand("select clobcol from clobtest where col1 =
1");
//OracleCommand cmd = new
OracleCommand("select sound from clobtest where col1 = 1");
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
OracleDataReader reader = null;
try
{
//cmd.ExecuteNonQuery();
// Create DataReader
reader = cmd.ExecuteReader
();
// Read the first row
while(reader.Read())
{
// Set the
OracleClob object to the CLOB selected
OracleClob clob =
reader.GetOracleClob(0);
//OracleBlob blob
= reader.GetOracleBlob(0);
String str3 =
clob.Value;
//String str4 =
blob.Value.Length.ToString();
//Label2.Text =
str4;
TextBox2.Text =
str3;
Label1.Text
= "Number of characters is " + str3.Length.ToString();
}
}
catch (Exception ex)
{
Console.WriteLine
("Exception:" + ex.Message);
}
finally
{
cmd.Dispose();
con.Close();
con.Dispose();
}
}
}
}
bebop
.