Informix byte 大对象的写入

来源:互联网 发布:淘宝网卖美女尿qq号 编辑:程序博客网 时间:2024/05/17 03:50
经过两天的研究与摸索,终于做出来Informix大对象的写入方法,成功了之后才发现代码很简单。
之前试过IBatis、构造sql、OleConnection、SqlConnection、导入DataTable、Update DataRow、甚至更改表结构放弃写入byte[]数据等很多方法,但是一一失败,
都盲目了,准备放弃了,但是
无意中发现IfxConnection这个连接,发现Ifx是Informix简写,所以就尝试使用IfxConnection,经过一番测试修改,终于成功了!真是山穷水复疑无路,柳暗花明又一村!
具体方法:
首先引入IBM.Data.Informix dll

//读文件构造
byte[]System.IO.FileStream stream = new System.IO.FileInfo(file).OpenRead();
byte[] fileData = new byte[stream.Length];
stream.Read(fileData, 0, Convert.ToInt32(stream.Length));
stream.Close();

//写入InformixIfxConnection connection = new IfxConnection("Database=niosdb;Host=IP;Server=XX;Service=8080; UID=userID;Password=password;"); //连接字符串
string sql = "insert into table_name(column1_name,column2_name) values(?,?)";
IfxCommand cm = new IfxCommand(sql, connection);
cm.Parameters.Add(new IfxParameter("column1_name",IfxType.VarChar,20)).Value = “XXXXX”; //string类型
cm.Parameters.Add(new IfxParameter("column2_name",IfxType.Byte)).Value = fileData; //byte[]类型
connection.Open();
cm.ExecuteNonQuery();
connection.Close();