将图片保存到SQL数据库中

来源:互联网 发布:unity3d 游戏关卡制作 编辑:程序博客网 时间:2024/05/19 22:00

为什么我保存图片(二进制)到数据库后,image类型的字段值为空?

表结构:

FingerInfo image

jfingeimage  image

JstudID varchar(10)

获取前台上传控件中的图片,

        int imgSize;//获取图片的大小        string imgType;//获取图片的格式。        StringBuilder stbFP = new StringBuilder();        Stream imgStream;//获取了一个InputStream流        imgSize = uploadfile1.PostedFile.ContentLength;        imgType = uploadfile1.PostedFile.ContentType;        imgStream = uploadfile1.PostedFile.InputStream;        byte[] imgContent = new byte[imgSize];        imgStream.Read(imgContent, 0, imgSize);        imgStream.Close();

 byte[]的长度为:74806

执行存储过程

 //创建一个SqlConnection对象         string strCon = ConfigurationManager.ConnectionStrings["datasource"].ToString();        SqlConnection myConn = new SqlConnection(strCon);        myConn.Open();        SqlCommand command = new SqlCommand();        command.Connection = myConn;        command.CommandText = "proc_StuFingerPrint";        command.CommandType = CommandType.StoredProcedure;        command.Parameters.Add("@FingerInfo", SqlDbType.Image).Value = fingerCode;        command.Parameters.Add("@jfingeimage", SqlDbType.VarChar).Value = imgContent; // imageBytes; //        command.Parameters.Add("@JstudID", SqlDbType.VarChar).Value = JstudID;        //command.Parameters.Add("@FingerNum", SqlDbType.VarChar).Value = FingerNum;        command.ExecuteNonQuery();        myConn.Close();

 执行后,并没有报错。但是到数据库中查看后,我发现 jfingeimage 这个image类型的字段为空。别的字段可以修改,谁知道是为什么?

 

原创粉丝点击