Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将映像上载到asp.net mvc5时,如何更正更新?_C#_Asp.net_Sql Server_Asp.net Mvc_C# 4.0 - Fatal编程技术网

C# 将映像上载到asp.net mvc5时,如何更正更新?

C# 将映像上载到asp.net mvc5时,如何更正更新?,c#,asp.net,sql-server,asp.net-mvc,c#-4.0,C#,Asp.net,Sql Server,Asp.net Mvc,C# 4.0,这是我使用sql server的数据库,我使用图像属性保存图像: create table registro(id int IDENTITY(1,1),Nombre varchar(100),appaterno varchar(100),apmaterno varchar(100),lineainvestigacion varchar(100),correo varchar(100),correoi varchar(100),telefonop int,extension int,telefo

这是我使用sql server的数据库,我使用图像属性保存图像:

 create table registro(id int IDENTITY(1,1),Nombre varchar(100),appaterno varchar(100),apmaterno varchar(100),lineainvestigacion varchar(100),correo varchar(100),correoi varchar(100),telefonop int,extension int,telefonoof int, usuario varchar(100) PRIMARY KEY ,clave varchar(100),imagen image,idrol varchar(100),ciudadr varchar(100));
这是我的班级:

public class Registro1
{

    public int id { get; set; }
    public string nombre { get; set; }
    public string appaterno { get; set; }
    public string apmaterno { get; set; }
    public string correo { get; set; }
    public string usuario { get; set; }
    public string clave { get; set; }

  // public string Imagen { get; set; }
    public byte[] imagen { get; set; }
    public string idrol { get; set; }
    
    
    public string lineainvestigacion { get; set; }
    public string correoi { get; set; }
    public int telefonoof { get; set; }
    public double telefonop { get; set; }
    public int extension { get; set; }
    public string ciudadr { get; set; }


}
这是我的控制器:

   public ActionResult Updateprofile(Registro1 rg)
        {
            connectionString();
            con.Open();
            com.Connection = con;
            com.CommandText =
 "update registro set Nombre='" + rg.nombre + "',ciudadr='" + rg.ciudadr + "',correoi='" + rg.correoi 
 + "',correo='" + rg.correo + "',clave='" + rg.clave + "',lineainvestigacion='" + 
 rg.lineainvestigacion + "',telefonop='" + rg.telefonop + "',extension='" + rg.extension + 
 "',telefonoof='" + rg.telefonoof + "',imagen='" + Convert.ToByte(rg.imagen) + "' WHERE usuario = '" 
 + rg.usuario + "'";






        try
        {


                dr = com.ExecuteReader();
                con.Close();
                Response.Write("<script>alert('Perfil actualizado')</script>");
                return View("../Home/Perfil");
           }
            catch (Exception es)
            {
              
                con.Close();
                Response.Write("<script>alert('Perfil no actualizado')</script>");
                return View("Actualizarperfil");

                throw es;
                // con.Close();

            }
        }
public ActionResult更新配置文件(Registro1 rg)
{
连接字符串();
con.Open();
com.Connection=con;
com.CommandText=
“更新注册表集Nombre=”+rg.Nombre+”,ciudadr=“+rg.ciudadr+”,correoi=”+rg.correoi
+“,correo=”+rg.correo+”,clave=“+rg.clave+”,lineInvestigacion=”+
rg.lineInvestigacion+“”,telefonop=“+rg.telefonop+”,extension=“+rg.extension+
“',telefonoof='”+rg.telefonoof+“',imagen='“+Convert.ToByte(rg.imagen)+“'WHERE usuario='”
+rg.usuario+“'”;
尝试
{
dr=com.ExecuteReader();
con.Close();
响应。写入(“警报('Perfil-actualizado')”;
返回视图(“../Home/Perfil”);
}
捕获(异常es)
{
con.Close();
响应。写入(“警报('Perfil no-actualizado')”;
返回视图(“执行视图”);
掷骰子;
//con.Close();
}
}
我命令如下调用我的图像属性

          <form action="Updateprofile" method="post" class="form-horizontal" role="form">
       

                 <div class="form-group">
                    <label for="Imagen" class="col-sm-3 control-label">Imagen</label>
                    <div class="col-sm-9">
                        <input type="file" name="Imagen" required />
                    </div>
                </div>

                <button type="submit" class="btn btn-primary btn-block">Actualizar datos</button>
 </form>

图像
萨尔达托斯酒店
但当我单击“更新”按钮时,它会显示以下错误:


我想知道我是否在控制器中错误地转换了字节属性,或者是否有其他错误

我想您应该使用
Convert.ToBase64String
来处理图像。可以找到该功能的文档


此外,连接字符串以创建SQL命令会打开SQL注入漏洞。您应该切换到。

这是一个正在提交的HTML表单,因此它将作为FormData发送。服务器需要从请求中提取文件,这样就有了像IFormFile或HttpPostedFileBase这样的接口。请检查这是否适用: