zoukankan      html  css  js  c++  java
  • 一个吐血的问题:上传图片参数无效

    c#中以二进制形式上传图片到数据库,在读取图片显示在PictureBox中时提示“参数无效”;找了很久终于发现问题所在:

    贴出代码:修改后代码

    OpenFileDialog oFd = new OpenFileDialog();
                if (oFd.ShowDialog() == DialogResult.OK)
                {
                    this.pictureBox1.Image = Image.FromFile(oFd.FileName);
                    this.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;

                   FileStream fs = new FileStream(oFd.FileName, FileMode.Open, FileAccess.Read);
                    byte[] buffByte = new byte[fs.Length];
                    fs.Read(buffByte, 0, (int)fs.Length);
                    fs.Close();

                     StringBuilder strSql = new StringBuilder();
                    strSql.Append("insert into EIIS_EVIDENCE_IMGS(");
                    strSql.Append("EVIDENCE_NO,EVIDENCE_IMG,ORGANIZATION_ID,DELETE_FLAG,CREATE_USER,CREATE_DATETIME,CURRENT_IMG,TRANSFER_ID)");
                    strSql.Append(" values (");
                    strSql.Append("@EVIDENCE_NO,@EVIDENCE_IMG,@ORGANIZATION_ID,@DELETE_FLAG,@CREATE_USER,@CREATE_DATETIME,@CURRENT_IMG,@TRANSFER_ID)");
                    strSql.Append(";select @@IDENTITY");
                    SqlParameter[] parameters = {
                       
         new SqlParameter("@EVIDENCE_NO", SqlDbType.VarChar,50),
         new SqlParameter("@EVIDENCE_IMG", SqlDbType.Image),
         new SqlParameter("@ORGANIZATION_ID", SqlDbType.Int,4),
         new SqlParameter("@DELETE_FLAG", SqlDbType.Char,1),
         new SqlParameter("@CREATE_USER", SqlDbType.VarChar,30),
         new SqlParameter("@CREATE_DATETIME", SqlDbType.DateTime),
         new SqlParameter("@CURRENT_IMG", SqlDbType.Char,1),
                        new SqlParameter("@TRANSFER_ID",SqlDbType.Int)
                                            };
                    parameters[0].Value = evi.EVIDENCE_NO;
                    parameters[1].Value = buffByte;
                    parameters[2].Value = GlobalClass.user.ORGANIZATION_ID;
                    parameters[3].Value = Convert.ToInt32(DeleteEnum.UnDelete).ToString();
                    parameters[4].Value = GlobalClass.user.USER_NO;
                    parameters[5].Value = DateTime.Now;
                    parameters[6].Value = Convert.ToInt32(YesOrNo.Yes).ToString();
                    parameters[7].Value = eviTransfer.TRANSFER_ID;
                    DataBase.SetBusinessConnection(GlobalClass.busiConnStr);
                    object obj = DataBase.GetScalar(strSql.ToString(), parameters);
                }

    修改后代码:

    OpenFileDialog oFd = new OpenFileDialog();
                if (oFd.ShowDialog() == DialogResult.OK)
                {
                    this.pictureBox1.Image = Image.FromFile(oFd.FileName);
                    this.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;

                   FileStream fs = new FileStream(oFd.FileName, FileMode.Open, FileAccess.Read);
                    byte[] buffByte = new byte[fs.Length];
                    fs.Read(buffByte, 0, (int)fs.Length);
                    fs.Close();

                     StringBuilder strSql = new StringBuilder();
                    strSql.Append("insert into EIIS_EVIDENCE_IMGS(");
                    strSql.Append("EVIDENCE_NO,EVIDENCE_IMG,ORGANIZATION_ID,DELETE_FLAG,CREATE_USER,CREATE_DATETIME,CURRENT_IMG,TRANSFER_ID)");
                    strSql.Append(" values (");
                    strSql.Append("@EVIDENCE_NO,@EVIDENCE_IMG,@ORGANIZATION_ID,@DELETE_FLAG,@CREATE_USER,@CREATE_DATETIME,@CURRENT_IMG,@TRANSFER_ID)");
                    strSql.Append(";select @@IDENTITY");
                    SqlParameter[] parameters = {
                       
         new SqlParameter("@EVIDENCE_NO", SqlDbType.VarChar,50),
         new SqlParameter("@EVIDENCE_IMG", SqlDbType.Image,16),
         new SqlParameter("@ORGANIZATION_ID", SqlDbType.Int,4),
         new SqlParameter("@DELETE_FLAG", SqlDbType.Char,1),
         new SqlParameter("@CREATE_USER", SqlDbType.VarChar,30),
         new SqlParameter("@CREATE_DATETIME", SqlDbType.DateTime),
         new SqlParameter("@CURRENT_IMG", SqlDbType.Char,1),
                        new SqlParameter("@TRANSFER_ID",SqlDbType.Int)
                                            };
                    parameters[0].Value = evi.EVIDENCE_NO;
                    parameters[1].Value = buffByte;
                    parameters[2].Value = GlobalClass.user.ORGANIZATION_ID;
                    parameters[3].Value = Convert.ToInt32(DeleteEnum.UnDelete).ToString();
                    parameters[4].Value = GlobalClass.user.USER_NO;
                    parameters[5].Value = DateTime.Now;
                    parameters[6].Value = Convert.ToInt32(YesOrNo.Yes).ToString();
                    parameters[7].Value = eviTransfer.TRANSFER_ID;
                    DataBase.SetBusinessConnection(GlobalClass.busiConnStr);
                    object obj = DataBase.GetScalar(strSql.ToString(), parameters);
                }

    就是在定义参数SqlParameter[] parameters 是把new SqlParameter("@EVIDENCE_IMG", SqlDbType.Image),写成了new SqlParameter("@EVIDENCE_IMG", SqlDbType.Image,16),
    晕到要死。真是低级。

  • 相关阅读:
    【LOJ #6397】【THUPC2018】—蛋糕 / Cake(DFS)
    【Atcoder Regular Contest 072F】—Dam(单调队列)
    【Atcoder Regular Contest 072F】—Dam(单调队列)
    多测师讲解自动化测试 _RF封装_(三层模式)高级讲师肖sir
    多测师讲解自动化测试 _RF关键字001_( 中)_高级讲师肖sir
    多测师讲解自动化测试 _RF分配id_高级讲师肖sir
    多测师讲解自动化--rf关键字--断言(下)_高级讲师肖sir
    多测师讲解自动化测试 _RF关键字001_(上)_高级讲师肖sir
    多测师讲解自动化测试 _RF模拟鼠标悬停_高级讲师肖sir
    多测师讲解自动化测试 _RF定位iframe框_高级讲师肖sir
  • 原文地址:https://www.cnblogs.com/shunliy/p/1279977.html
Copyright © 2011-2022 走看看