需求如下:用编号对应数据库中的图片,在输入编号时,能够查询出片,并且能将图片打印出来。求DEMO,希望每行都有注释,谢谢各位。本人菜鸟,望各位担待。

解决方案 »

  1.   

    图片是二进制保存还是图片地址,地址直接sqlconnection
    image绑定图片
    string sqlstr = "select photo from Tb where id=@id";
      SqlConnection myConnection = new SqlConnection(connstr);
      SqlCommand cmd= new SqlCommand(sqlstr, myConnection);
    cmd.AddWithValue("@id",strImageID )
      myConnection.Open();
      SqlDataReader dr= cmd.ExecuteReader(CommandBehavior.CloseConnection);
      if(dr.Read())
      {
      Response.Clear();
      Response.ContentType = "image/gif";
      Response.BinaryWrite((byte[])dr["photo"]);
      }
      myConnection.Close();
      

  2.   

    并且能将图片打印出来是指在界面上显示还是真的使用打印机打印出来?
    如果只是显示,加一个picturebox,设置image属性