软件:VS2008、SQL Server 2005
C#的编写的窗体,需要显示数据库里的一个表格,这个已经可以做到。表格里面有一列的数据类型是picture,我想插入小图标。本人还是菜鸟,希望大家帮帮我!

解决方案 »

  1.   

      在数据库中定义图片类型未string型的,把你要插入的图片路劲插入数据库中,,只要路劲没错,在页面绑定就可以出来
      

  2.   

    一般先将图片转成byte[],再将byte[]做参数,Sql语句也要写成参数形式的,插入数据库
    读取的时候相反,先读取出byte[],再根据此byte[]构建一个Image
      

  3.   

        private byte[] Ime2byte(string filePath)
        {
          if (File.Exists(filePath))
          {
            FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            byte[] byteImage = new byte[fileStream.Length];
            fileStream.Read(byteImage, 0, (int)fileStream.Length);
            return byteImage;
          }
          else
          { return null; }
        }把这个 byteImage这个存入数据库就可以了
      

  4.   

    http://topic.csdn.net/u/20101229/20/cdc22e1d-975b-4f88-a6bf-fbad31e0e3da.html
      

  5.   

    这是插入access的例子。你改改可以用到sql中。
    OleDbConnection cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=db.mdb");
                            cn.Open();
                            OleDbCommand cmd = new OleDbCommand("insert into product (p_name,p_hid,p_pic,p_bz,p_pice,l_id) values ('测试','001',@i,'001','12','" + inc + "')", cn);
                            byte[] ib = new Byte[6000000];
                            FileStream fs = new FileStream(nowload, FileMode.Open, FileAccess.Read);
                            fs.Read(ib, 0, 6000000);
                            cmd.Parameters.Add("@i", OleDbType.Binary, (int)fs.Length);
                            cmd.Parameters["@i"].Value = ib;
                            cmd.ExecuteNonQuery();
                            cn.Close();