文件插入IMAGE字段:首先将文件转换成二进制流,然后再Insert 
        private byte[] FileToByte(string filePath)
        {//将文档转换成二进制流
            //创建字节空间 
            byte[] ib = new Byte[60000];
            //获取上传的图片的路径 
            string strfilepath = filePath;
            //转换成文件流 
            FileStream fs = new FileStream(strfilepath, FileMode.Open, FileAccess.Read);
            //将文件内容读进字节数组 
            fs.Read(ib, 0, 60000);
            return ib;
        }

解决方案 »

  1.   

    通过byte[]数组来操作。
    把图片转成byte[],然后用
      insert into 表名(Image字段名) values (@Image)
    这样的方法,把byte[]作为参数就可以新增。修改也一样查询:(byte[])datareader["ImageField"]得到数据,然后转成Image显示。
      

  2.   

    图片在数据库中的存储是以byte[]来传递,byte[]与Image的转换可以使用System.Drawing.ImageConvert类去处理
      

  3.   

    private void button1_Click(object sender, EventArgs e)//上传图片
            {
                OpenFileDialog openFileDialog1 = new OpenFileDialog();
                openFileDialog1.Filter = "图像文件 (*.BMP;*.JPG;*.GIF;*.PNG)|*.BMP;*.JPG;*.GIF;*.PNG";
                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 sqlconnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Football_Vs.Properties.Settings.footballConnectionString"].ConnectionString);
                    sqlconnection.Open();
                    SqlCommand com = new SqlCommand("update TeamImages set teamimage=@ImageList where teamname='" + TeamCombo.Text + "'", sqlconnection);
                    com.Parameters.Add("ImageList",SqlDbType.Image);
                    com.Parameters["ImageList"].Value = imagebytes;
                    com.ExecuteNonQuery();
                    MessageBox.Show("上传成功");
                    sqlconnection.Close();
                    displayPhoto();
                }
            }        private void displayPhoto()//显示图片
            {
                byte[] imagebytes = null;
                DBOperate dbop = new DBOperate();
                string selectStr = "select teamimage from teamimages where teamname='" + TeamCombo.Text + "'";
                SqlDataReader dr = dbop.displayTeam(selectStr);
                dr.Read();
                if (dr.HasRows)
                {
                    switch (dr[0].ToString())
                    {
                        case "":
                            pictureBox1.Image = null;
                            break;
                        default:
                            imagebytes = (byte[])dr.GetValue(0);
                            dr.Close();
                            MemoryStream ms = new MemoryStream(imagebytes);
                            Bitmap bmpt = new Bitmap(ms);
                            pictureBox1.Image = bmpt;
                            break;
                    }
                }
                else
                {
                    pictureBox1.Image = null;
                }
                dr.Close();
            }