在C#中从SQL Server检索图像
问题描述:
using (SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Documents and Settings\\meekun.poon\\My Documents\\Visual Studio 2008\\Projects\\TrackLocation\\TrackLocation\\barcodePrinter.mdf;Integrated Security=True;User Instance=True"))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("SELECT ImageName FROM Image WHERE ImageID='PL001'", conn))
{
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
DataSet dataSet = new DataSet();
adpt.Fill(dataSet, "Image");
DataRow Row;
Row = dataSet.Tables["Image"].Rows[0];
byte[] MyImg = (byte[])Row[0];
MemoryStream ms = new MemoryStream(MyImg);
ms.Position = 0;
Image img = Image.FromStream(ms); //error
pictureBox1.Image = img;
}
conn.Close();
}
如何解决这个问题呢??? imagename是图像数据类型!错误消息->参数无效.紧急!!!感谢
how to solve this problem??? imagename is image data type!! error message->parameter is not valid. URGENT!!! thanks
答
看看这个:
> http://*.com/questions/2175209/retrieve-images-from-sql-服务器数据库 [ ^ ]
还有这个:
使用Streded Procedures和C#.net从SQL Server存储和检索图像 [ ^ ]
Have a look at this:
http://*.com/questions/2175209/retrieve-images-from-sql-server-database[^]
and this as well:
Storing and Retrieving Images from SQL Server Using Strored Procedures and C#.net[^]