【发布时间】:2016-01-17 04:21:47
【问题描述】:
我在 Sql Server 2008 中有一个名为 PhotoStorages 的表,其中包含以下列。此表包含 5000 条数据。
PhotoStorageId bigint
Photo image
目前我正在使用 C# 加载数据,如下所示
string sql = "SELECT * FROM PhotoStorages";
using (SqlCommand sqlCommand = new SqlCommand(sql))
{
using (SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlCommand))
{
using (DataTable dataTable = new DataTable())
{
dataAdapter.Fill(dataTable);
if (dataTable.Rows.Count > 0)
{
for (int i = 0; i < dataTable.Rows.Count; i++)
{
/*Resize the image and again update those resized image to the same database table*/
}
}
}
}
}
现在这个过程的执行速度很慢。我想知道是否有任何替代方法可以实现这一目标。提前致谢!
【问题讨论】:
-
我其实认为调整图像大小的代码是最重要的!请为我们添加!
-
很可能 99% 的缓慢过程发生在您已注释掉的部分。从数据库加载 5000 行可能只需要几毫秒。 SQL 连接只需要几毫秒,而且很少。因此,我建议您发布调整大小代码的内容。
-
@JamesHay 我认为如果您获得 5000 行包含字节树数据的行,它不会花费几毫秒...
-
@JamesHay:照片列包含大尺寸的图像。所以需要更多的时间。在 sql server 本身中,执行 select 查询需要 10 多分钟。
-
你这里真的需要数据适配器和数据表吗,我认为在你的情况下使用简单的数据阅读器将是完美的。