You can write a character large object (CLOB) to a database as character data, depending on the type of field at your data source. To write a CLOB value to your database, issue the appropriate INSERT or UPDATE statement and pass the CLOB value as an input parameter.
The following code example adds employee information to the Employees table in the DEMODB database. A resume of the employee is read from a file and added to the resume field in the table.
| Note |
|---|
|
You need to using CREATE TABLE statement to create a table, the table name is Employees. The SQL statement: create table Employees(resume CLOB, id int); |
using CUBRID.Data.CUBRIDClient;
namespace BLOBExample
{
class Program
{
static void Main(string[] args)
{
CUBRIDConnectionStringBuilder sb = new CUBRIDConnectionStringBuilder("localhost", "demodb", "public", "", "33000", true);
using (CUBRIDConnection conn = new CUBRIDConnection(sb.GetConnectionString()))
{
conn.Open();
string sql = "insert into Employees(resume) values(?)";
using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
{
StreamReader _reader = new StreamReader(File.Open(@".\John.txt", FileMode.Open));
string _resume = _reader.ReadToEnd();
_reader.Close();
CUBRIDBlob Blob = new CUBRIDBlob(conn);
Clob.setString(1, _resume);
CUBRIDParameter param = new CUBRIDParameter();
param.ParameterName = "?";
param.CUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_CLOB;
param.Value = Blob;
cmd.Parameters.Add(param);
cmd.ExecuteNonQuery();
cmd.Close();
}
conn.Close();
}
}
}
}