我已經創建了將映像上載到SQL Server的代碼。嘗試將映像保存到SQL Server時出錯
這裏是將圖像轉換成字節代碼:
//Use FileInfo object to get file size.
FileInfo fInfo = new FileInfo(p);
//Open FileStream to read file
FileStream fStream = new FileStream(p, FileMode.Open, FileAccess.Read);
byte[] numBytes = new byte[fStream.Length];
fStream.Read(numBytes, 0, Convert.ToInt32(fStream.Length));
//Use BinaryReader to read file stream into byte array.
//BinaryReader br = new BinaryReader(fStream);
//When you use BinaryReader, you need to supply number of bytes to read from file.
//In this case we want to read entire file. So supplying total number of bytes.
// data = br.ReadBytes((int)numBytes);
return numBytes;
這裏是字節添加到SqlCommand
參數作爲值碼:
objCmd.Parameters.Add("@bill_Image", SqlDbType.Binary).Value = imageData;
objCmd.ExecuteNonQuery();
但我得到錯誤
字符串或二進制數據將被截斷。聲明已被終止
我該如何克服這個問題?
SQL Server中的列大小是什麼?該錯誤基本上告訴您,您正在嘗試存儲比列中允許的更多字節。 – Icarus 2013-03-15 13:39:51
如果你的列長度已經是'max',那麼檢查表中是否有觸發器? – 2013-03-15 13:42:03
我已經將列更改爲Max,並且我沒有使用表中的觸發器 – jeevacl 2013-03-15 15:01:52