我需要将图片从数据库读取出来,显示在pictureBox1中!!
错误为:参数无效!如何解决!求大神帮忙!!!!!
代码如下!!!!
 
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient;
using System.IO;namespace form
{
    public partial class Tetal : Form
    {
        private string connectString = ConfigurationManager.AppSettings["ConnectString"].ToString();
        //连接对象
        private SqlConnection conn;
        //命令对象
        private SqlCommand cmd;
        //数据读取器
        private SqlDataReader dr;        public Tetal()
        {
            InitializeComponent();
        }        private void Tetal_Load(object sender, EventArgs e)
        {
            ima();
        }
         private void ima()
        {            try
            {
                //创建数据库连接字符串
                conn = new SqlConnection(connectString);
                //打开数据库连接
                conn.Open();
                //创建SQL语句
                SqlCommand cmd = new SqlCommand("select account,images from Login order by account",conn); 
                //string sql = "select account,images from Login";
                ////string sql = "select images from Login where account="+av;
                ////创建SqlCommand对象
                //SqlCommand cmd = new SqlCommand(sql, conn);
                //创建DataAdapter对象
                SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd);
                //创建DataSet对象
                DataSet dataSet = new DataSet();
                dataAdapter.Fill(dataSet, "Login");
                int c = dataSet.Tables["Login"].Rows.Count;
                if (c > 0)
                {
                    Byte[] mybyte = new byte[0];
                    mybyte = (Byte[])(dataSet.Tables["Login"].Rows[c - 1]["images"]);
                    MemoryStream ms = new MemoryStream(mybyte);
                    pictureBox1.Image = Image.FromStream(ms);
                }
                conn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }        }

解决方案 »

  1.   

      MemoryStream stream = new MemoryStream(b, true);
         stream.Write(b, 0, b.Length);
         pictureBox1.Image = new Bitmap(stream);
         stream.Close();
      

  2.   


    或者
    MemoryStream buf=new MemoryStream(mybyte);
    Image image=Image.FromStream(buf,true);
    pictureBox1.Image=image;
      

  3.   

    那个参数无效?
    images 可能本身就是null
      

  4.   

    Byte[] mybyte = (Byte[])(dataSet.Tables["Login"].Rows[c - 1]["images"]);错误:
    Byte[] mybyte = new byte[0]; 
      

  5.   


    数据库里面,images字段,有数据的!!!