저는 Windows Form에 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();
보통
항상 작동하지만 : 그림 열
데이터 유형이 표에 '이미지'는 'TABLENAME'
이 여기에 데이터베이스에서 이미지를 가지고 PictureBox
제어에 넣어 말한다 코드입니다 과 오류 'Paramerter is not valid'이 (가) 표시됩니다. pictureBox1.Image = Image.FromStream(stream);
이해가되지 않습니까? 어떤 매개 변수?
도움이 될 것입니다.
db 쿼리가 유효한 결과를 반환하는지 확인 했습니까? – Mate
예, 유효한 결과가 표시됩니다. 내 유일한 문제는 PictureBox가 MemoryStreams 개체에서 이미지를 가져 오지 않는다는 것입니다. – shanu