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();
             }
         }
     }
 }
 
 
 
 
 
 
 
 
 
posted @ 2016-03-17 17:12  过错  阅读(208)  评论(0编辑  收藏  举报