Informix byte 大對象的寫入

經過兩天的研究與摸索,終於做出來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();  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章