CUBRID学习笔记 40 使用net修改数据
修改
connection.Open();
string
queryString =
"UPDATE nation set capital = 'X' where `code` = 'A'"
;
CUBRIDCommand command =
new
CUBRIDCommand(queryString, connection);
Int32 recordsAffected = command.ExecuteNonQuery();
删除
// Assumes connection is a valid SqlConnection.
connection.Open();
string
queryString =
"DELETE FROM nation where `code` = 'A'"
;
CUBRIDCommand command =
new
CUBRIDCommand(queryString, connection);
Int32 recordsAffected = command.ExecuteNonQuery();
写入blob类型数据
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 (Photo) values(?)"
;
using
(CUBRIDCommand cmd =
new
CUBRIDCommand(sql, conn))
{
CUBRIDBlob Blob =
new
CUBRIDBlob(conn);
byte
[] bytes;
BinaryReader _reader =
new
BinaryReader(File.Open(
@".\John.jpg"
, FileMode.Open));
int
length = (
int
)_reader.BaseStream.Length;
bytes = _reader.ReadBytes(length);
Blob.setBytes(1, bytes);
CUBRIDParameter param =
new
CUBRIDParameter();
param.ParameterName =
"?"
;
param.CUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_BLOB;
param.DbType = DbType.Binary;
param.Value = Blob;
cmd.Parameters.Add(param);
cmd.ExecuteNonQuery();
}
conn.Close();
}
}
}
}
写入clob数据
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();
}
}
}
}
作者:过错
出处:http://www.cnblogs.com/wang2650/
关于作者:net开发做的久而已。十余年时光虚度!
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。如有问题,可以邮件:wang2650@163.com
联系我,非常感谢。