System.ArgumentException:“参数无效。”

winform中获取数据库上传的图片在前台显示是报错。具体代码如下:

HaiJiYaBLL.UserBLL bll = new HaiJiYaBLL.UserBLL();

            HaiJiYaModel.UserInfo model = bll.GetUserInfo(id);

            txtRelName.Text = model.UserName1;
            txtRelName.ReadOnly = true;
            txtLoginName.ReadOnly = true;
            txtLoginName.Text = model.LoginName1;
            if (model.UserSex1 == "女")
            {
                radio_women.Checked = true;
            }
            if (model.UserBirth1 == null || model.UserBirth1 == DateTime.MinValue)
            {
                dtpcstime.Value = DateTime.Now;
            }
            else
            {
                dtpcstime.Value = model.UserBirth1;
            }

            txtsfzh.Text = model.UsersfID1;
            txtjtzz.Text = model.UserDZ1;
            cbomz.Text = model.Usermz1;
            tztgszw.Text = model.Userzw1;
            txtlxdh.Text = model.UserPhone1;
            txtyx.Text = model.UserEmail1;
            txtyb.Text = model.Useryb1;

            if (model.ImgUrl1 != null)
            {
                byte_Image2 = (byte[])(model.ImgUrl1);
                MemoryStream ms = new MemoryStream(byte_Image2);
                pictureBox1.Image = Image.FromStream(ms);
            }

报错语句:

pictureBox1.Image = Image.FromStream(ms);

bll中GetUserInfo的代码为:

public UserInfo GetUserInfo(int UID)
        {
            return userdal.GetUserInfo(UID);
        }

userdal中GetUserInfo的代码如下:

     public UserInfo GetUserInfo(int UID)
        {
            StringBuilder sbr = new StringBuilder();
            sbr.Append("select * from tablename");
            sbr.Append(" where UID = @UID");

            SqlParameter[] sqlp = {
                new SqlParameter("@UID",SqlDbType.Int,5),
            };
            sqlp[0].Value = UID;

            UserInfo model = new UserInfo();
            DataSet ds = SQLDBHelp.DateSet(sbr.ToString(), sqlp);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["UID"].ToString() != "")
                {
                    model.UID1 = int.Parse(ds.Tables[0].Rows[0]["UID"].ToString());
                }
                model.LoginName1 = ds.Tables[0].Rows[0]["LoginName"].ToString();
                model.UserSex1 = ds.Tables[0].Rows[0]["UserSex"].ToString();
                if (model.UserBirth1 == null || model.UserBirth1 == DateTime.MinValue)
                {
                    model.UserBirth1 = DateTime.Now;
                }
                else
                {
                    model.UserBirth1 = Convert.ToDateTime(ds.Tables[0].Rows[0]["UserBirth"]);
                }
                model.UsersfID1 = ds.Tables[0].Rows[0]["UsersfID"].ToString();
                model.UserDZ1 = ds.Tables[0].Rows[0]["UserDZ"].ToString();
                model.Usermz1 = ds.Tables[0].Rows[0]["Usermz"].ToString();
                model.Userzw1 = ds.Tables[0].Rows[0]["Userzw"].ToString();
                model.UserPhone1 = ds.Tables[0].Rows[0]["UserPhone"].ToString();
                model.UserEmail1 = ds.Tables[0].Rows[0]["UserEmail"].ToString();
                model.Useryb1 = ds.Tables[0].Rows[0]["Useryb"].ToString();
                model.ImgUrl1 = (byte[])ds.Tables[0].Rows[0]["ImgUrl"];


                model.UserPassWord1 = ds.Tables[0].Rows[0]["UserPassWord"].ToString();
                if (ds.Tables[0].Rows[0]["UserBirth"].ToString() != "")
                {
                    model.UserBirth1 = DateTime.Parse(ds.Tables[0].Rows[0]["UserBirth"].ToString());
                }

                if (ds.Tables[0].Rows[0]["ImgUrl"].ToString() != "")
                {
                    model.ImgUrl1 = (byte[])ds.Tables[0].Rows[0]["ImgUrl"];
                }

                return model;
            }
            else {
                return null;
            }
        }

求大神指点一下,急等!!!

查看全部
Jasonchne
Jasonchne
2019/03/27 16:39
  • c#
  • visual studio
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复