SQL 데이터베이스에서 이미지를 검색하는 중 여전히 문제가 있습니다. 이것은 데이터베이스에서 이미지를 삽입하고 검색하는 최종 솔루션입니다. 여기에 내 모든 코드는 다음과 같습니다
GUI 부분 :sqldatabase에서 이미지를 검색하기 위해이 코드를 수정하십시오.
protected void BtnSave_Click(object sender, EventArgs e)
{
string uploadFileName = string.Empty;
byte[] imageBytes = null;
if (imageUpload != null && imageUpload.HasFile)
{
uploadFileName = imageUpload.FileName;
imageBytes = imageUpload.FileBytes;
}
string str = ConfigurationManager.ConnectionStrings["ImageConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(str);
SqlCommand com = new SqlCommand("INSERT INTO REPORT_TABLE (IMAGEFIELD,IMAGENAME) VALUES (@image,@filename)", con);
com.Parameters.Add("@image", SqlDbType.Image, imageBytes.Length).Value = imageBytes;
com.Parameters.Add("@filename", SqlDbType.VarChar, 50).Value = uploadFileName;
con.Open();
com.ExecuteNonQuery();
con.Close();
SqlConnection conn = new SqlConnection(str);
string sql = "SELECT * FROM [REPORT_TABLE]";
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds);
DataRow dr = ds.Tables[0].Rows[0];
Byte[] b = (Byte[])dr["IMAGEFIELD"];
MemoryStream ms = new MemoryStream(b);
**this.pictureBox1.Image = Image.FromStream(ms)**; //(This code is for a Windows application but I want to retrieve an image from a web application) so what should be written instead of the highlighted code? In imagecontrol, image id is Image1.
}
을 어쨌든 내가 질문을 업데이트가 다음과 같이
지금 업로드 페이지에서 당신 버튼 클릭을 변경 :) :) –