图片保存到数据库和从数据库读取图片并显示(c#)

时间:2008-04-19 10:35:50   来源:  作者:

        public void imgToDB(string sql)
        {   //参数sql中要求保存的imge变量名称为@images
            //调用方法如:imgToDB("update UserPhoto set Photo=@images where UserNo='" + temp + "'");
            FileStream fs = File.OpenRead(t_photo.Text);
            byte[] imageb = new byte[fs.Length];
            fs.Read(imageb, 0, imageb.Length);
            fs.Close();
            SqlCommand com3 = new SqlCommand (sql,con);
            com3.Parameters.Add("@images", SqlDBType.Image).Value = imageb;
            if (com3.Connection.State == ConnectionState.Closed)
                com3.Connection.Open();
            try
            {
                com3.ExecuteNonQuery();
            }
            catch
            { }
            finally
            { com3.Connection.Close(); }

 1/4    1 2 3 4 ›› ›|
关键字:图片保存

文章评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面