如何更新 SQL Server 2008 中的 BLOB 列,我正在尝试使用 Like 进行模式匹配并希望更新该列。
问问题
2883 次
2 回答
0
来自http://www.akadia.com/services/dotnet_read_write_blob.html:
// Read Image into Byte Array from Filesystem
byte[] photo = GetPhoto(photoFilePath);
// Construct INSERT Command
SqlCommand addEmp = new SqlCommand(
"INSERT INTO Employees ("+
"LastName,FirstName,Title,HireDate,ReportsTo,Photo) "+
"VALUES(@LastName,@FirstName,@Title,@HireDate,@ReportsTo,@Photo)",_conn);
addEmp.Parameters.Add("@LastName", SqlDbType.NVarChar, 20).Value = plastName;
addEmp.Parameters.Add("@FirstName", SqlDbType.NVarChar, 10).Value = pfirstName;
addEmp.Parameters.Add("@Title", SqlDbType.NVarChar, 30).Value = ptitle;
addEmp.Parameters.Add("@HireDate", SqlDbType.DateTime).Value = phireDate;
addEmp.Parameters.Add("@ReportsTo", SqlDbType.Int).Value = preportsTo;
addEmp.Parameters.Add("@Photo", SqlDbType.Image, photo.Length).Value = photo;
// Open the Connection and INSERT the BLOB into the Database
_conn.Open();
addEmp.ExecuteNonQuery();
_conn.Close();
// **** Read Image into Byte Array from Filesystem
public static byte[] GetPhoto(string filePath)
{
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
byte[] photo = br.ReadBytes((int)fs.Length);
br.Close();
fs.Close();
return photo;
}
如果您的文档是:您可以进行全文搜索:
.doc
.txt
.xls
.ppt
.htm
参考: http ://technet.microsoft.com/en-us/library/cc917636.aspx
于 2012-05-29T20:33:35.390 回答
0
更新 blob 没问题,您只需更新它。“我正在尝试与 Like 进行模式匹配,并希望更新该列。” 这是不可能的。您无法搜索 blob。有复杂的解决方法。您可以启用全文搜索可能是最简单的。如果您有一个玩具数据库并且一开始并不真的需要 blob,您可以将其转换为 nvarchar(4000) 并搜索它,这将逐行进行转换,进行非常缓慢的搜索,并且仅在以下情况下才有效您要查找的是前 4000 个字符。
于 2012-05-29T20:40:37.647 回答