我在我的Windows窗體中有一個PictureBox
控制。
數據類型圖片列中是「形象」表「表名」
這些在這裏是說,從數據庫中取圖像,並把它放在PictureBox
控制代碼:無法檢索圖像從數據庫到圖片框
string connectionString = @"Initial Catalog=DataBaseName;Data Source=DataSourceName;Integrated Security=SSPI;";
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
SqlDataAdapter da = new SqlDataAdapter(new SqlCommand("Select Picture From TableName where ID = 2 ", connection));
DataSet ds = new DataSet();
da.Fill(ds);
byte[] myImage = new byte[0];
myImage = (byte[])ds.Tables[0].Rows[0]["Picture"];
MemoryStream stream = new MemoryStream(myImage);
pictureBox1.Image = Image.FromStream(stream);
connection.Close();
通常它始終工作,但現在它的顯示ArgumentExeption
錯誤'Paramerter is not valid'at this line pictureBox1.Image = Image.FromStream(stream);
我不明白?哪個參數?
任何幫助將不勝感激。
您是否已檢查數據庫查詢是否返回有效結果? – Mate
是的,它顯示有效的結果。我唯一的問題是PictureBox沒有從MemoryStreams對象中獲取圖像。 – shanu