大对象
下面的示例将展示读取一张图片到并保存到数据库中。图片以二进制数据存储在
PRODUCT 表中的 PHOTO 字段中。
using System; using System.Collections.Generic; using System.IO; using System.Text; using Dm; namespace DMDemo { class BinaryDemo { //返回结果 static int ret = 1; static DmConnection cnn = new DmConnection(); [STAThread] static int Main(string[] args) { try { cnn.ConnectionString = "Server=localhost; User Id=SYSDBA; PWD=SYSDBA"; cnn.Open(); BinaryDemo demo = new BinaryDemo(); demo.TestFunc(); cnn.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadLine(); return ret; } public void TestFunc() { DmCommand command = new DmCommand(); command.Connection = cnn; try { FileInfo fi = new FileInfo(@"F:\dotnet\dameng\DM 数据库例子\三国演义.jpg"); FileStream fs = fi.OpenRead(); int nBytes = (int)fs.Length; byte[] dataArray = new byte[nBytes]; fs.Read(dataArray, 0, nBytes); fs.Close(); command.CommandText = "UPDATE PRODUCTION.PRODUCT SET PHOTO = :PHOTO WHERE PRODUCTID = 11"; DmParameter parm1 = command.Parameters.Add(":PHOTO", DmDbType.Binary); parm1.Value = dataArray; command.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine(ex.Message); ret = 0; } } } }
https://xpanx.com/
评论