如题,望高手帮忙~

解决方案 »

  1.   

    再从数据库中取出来放在DATAGRIDVIEW列中
      

  2.   

    在表中显示为长二进制数据。存时转成Byte流http://www.cnblogs.com/chenkai/archive/2010/02/03/1662542.html
      

  3.   

      image类型的数据???
      

  4.   


           public bool Add_Spxx(c_spxx spxx)
            {
                try
                {
                    bool flag = false;
                    string sql = "EXEC hyxs_spxx_ADD @spbh,@spmc,@tp";
                    SqlParameter[] para = new SqlParameter[]{
                     new SqlParameter("@spbh",spxx.spbh),
                     new SqlParameter("@spmc",spxx.spmc),
                     new SqlParameter("@tp",spxx.tp) //图片
                    };
                    if (DbHelperSQL.GetScalar(sql, para) == 0)
                    {
                         flag = true;
                    }
                    return flag;
                }
                catch (Exception ce)
                {
                    throw ce;
                }
                finally
                {
                    DbHelperSQL.ConnClose();
                }
            }
      

  5.   

    #region 把指定图片转换为byte
            /// <summary>
            /// 把指定图片转换为byte
            /// </summary>
            /// <param name="path">图形路径</param>
            /// <returns></returns>
            public static byte[] GetPhoto(string path)
            {
                string str = path;
                byte[] photo = new byte[0];
                if (File.Exists(path))
                {
                    FileStream file = new FileStream(str, FileMode.Open, FileAccess.Read);
                    photo = new byte[file.Length];
                    file.Read(photo, 0, photo.Length); file.Close(); } return photo;
            }
            #endregion
      

  6.   

    Stream ms;
      byte[] picbyte;
      OpenFileDialog ofdSelectPic = new OpenFileDialog();
      if (ofdSelectPic.ShowDialog() == DialogResult.OK)
      {
      if ((ms = ofdSelectPic.OpenFile()) != null)
      {
      picbyte = new byte[ms.Length];
      ms.Position = 0;
      ms.Read(picbyte, 0, Convert.ToInt32(ms.Length));
      SqlConnection conn = new SqlConnection();
      conn.ConnectionString = "";  sql = "Insert into Person(Photo) values(@Image)";
      SqlCommand cmd = new SqlCommand(sql, conn);  cmd.Parameters.Add("@Image", SqlDbType.VarBinary);
      cmd.Parameters["@Image"].Value = picbyte;  conn.Open();
      cmd.ExecuteNonQuery();
      conn.Close();  ms.Close();
      }
      } SqlConnection conn=new SqlConnection();   
     conn.ConnectionString="";   
     string strSql="";   
     SqlCommand cmd=new SqlCommand(strSql,conn);   
     conn.Open();   
     SqlDataReader reader=cmd.ExecuteReader();   
      reader.Read();   
     MemoryStream ms=new MemoryStream((byte[])reader["Photo"]);   
     Image image=Image.FromStream(ms,true);   
     reader.Close();   
     conn.Close();   
     picturebox1.Image=image;   
    FileStream mystream=new FileStream("D:\\A.jpg",FileMode.Open,FileAccess.Read);
    long len=mystream.Length;
    mycmd.Parameters.Add("@image",SqlDbType.Image,(int)len,"picture");
    mycmd.Parameters["@image"].Direction=System.Data.ParameterDirection.Input;
    byte []box=new byte[len];   
    mystream.Read(box,0,(int)len);
    mycmd.Parameters["@image"].Value=box;
      

  7.   

    我有源码,如果要的话请联系我QQ29992379,或者是在CSDN上留言
      

  8.   

    wildfeng04麻烦你把源码贴一下~谢谢啊!
      

  9.   

    1、图片存入数据库
    本实例主要介绍如何将图片存入数据库。将图片存入数据库,首先要在数据库中建立一张表,将存储图片的字段类型设为Image类型,用FileStream类、BinaryReader把图片读成字节的形式,赋给一个字节数组,然后用ADO.SqlCommand对象的ExecuteNonQuery()方法来把数据保存到数据库中。主要代码如下:
    /// <summary>
            /// 将图片以二进制读入数据库
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void button1_Click(object sender, EventArgs e)
            {
                openFileDialog1.Filter = "*jpg|*.JPG|*.GIF|*.GIF|*.BMP|*.BMP";
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    string fullpath = openFileDialog1.FileName;//文件路径
                    FileStream fs = new FileStream(fullpath, FileMode.Open);
                    byte[] imagebytes = new byte[fs.Length];
                    BinaryReader br = new BinaryReader(fs);
                    imagebytes = br.ReadBytes(Convert.ToInt32(fs.Length));
                    //打开数所
                    SqlConnection con = new SqlConnection("server=(local);database=zy_info;integrated security=true");
                    con.Open();
                    SqlCommand com = new SqlCommand("insert into tb_text  values(@guatu)", con);
                    //"update yijing set guatu='"+
                    com.Parameters.Add("guatu", SqlDbType.Image);
                    com.Parameters["guatu"].Value = imagebytes;
                    com.ExecuteNonQuery();
                    con.Close();
                    MemoryStream ms = new MemoryStream(imagebytes);
                    Bitmap bmpt = new Bitmap(ms);
                    this.pictureBox1.Image = bmpt;
                }     
            }
    2、图片读出数据库
    /// <summary>
            /// 读出二进制图片数据
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void button2_Click(object sender, EventArgs e)
            {
                byte[] imagebytes = null;
                //打开数据库
                SqlConnection con = new SqlConnection("server=(local);database=zy_info;integrated security=true");
                con.Open();
                SqlCommand com = new SqlCommand("select top 1* from tb_text", con);
                SqlDataReader dr = com.ExecuteReader();
                while (dr.Read())
                {
                    imagebytes = (byte[])dr["guatu"];
                }
                dr.Close();
                com.Clone();
                con.Close();
                MemoryStream ms = new MemoryStream(imagebytes);
                Bitmap bmpt = new Bitmap(ms);
                this.pictureBox1.Image = bmpt;
                //dr.Close();
                //com.Clone();
                //con.Close();
            }
    这个可以成功的!
      

  10.   

    谢谢大家的帮忙!不过分还是给guoyanhong1111,呵呵