我有这个问题,插入图像到我的数据库可以有人帮忙吗? [英] I'm having this problem to inserting image to my DB can anyone help?
本文介绍了我有这个问题,插入图像到我的数据库可以有人帮忙吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个.NetFrame工作错误列表
This the .NetFrame work error list
An exception of type 'System.Data.SqlClient.SqlException' occurred in Brp.Core.dll but was not handled in user code
Additional information: Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.
这是我的模型:
This is my model:
//[Required]
public byte[] Passport { get; set; }
/*[Required]
[DataType(DataType.ImageUrl)]
public string BusinessLogo { get; set; }*/
//[Required]
public byte[] BusinessLogo { get; set; }
[ScaffoldColumn(false)]
//[Column]
public string ImageMimeType { get; set; }
[ScaffoldColumn(false)]
//[Column]
public string ImageMimeType2 { get; set; }
这是我的续集
This my sequel
SqlConnection con = new SqlConnection(@"Data Source=(localdb)\v11.0;Initial Catalog=Bpr;Integrated Security=True");
SqlCommand cmd = new SqlCommand();
cmd.CommandText = String.Format("Insert into Payer(User_Id, PayerName, BusinessName,PhoneNumber,BusinessMobile,PayerAddress,NumberOfStaff,RegDate,DateOfBirth,LocationLatLog,Passport,StateOfOrigin,BusinessLogo, ImageMimeType, ImageMimeType2) values('" + payer.User_Id + "','" + payer.PayerName + "','" + payer.BusinessName + "','"
+ payer.PhoneNumber + "','"+payer.BusinessMobile + "','" + payer.PayerAddress + "','" +payer.NumberOfStaff + "','" +
payer.RegDate + "','" + payer.DateOfBirth + "','" + payer.LocationLatLog + "','" + payer.Passport + "','"
+ payer.StateOfOrigin + "','" + payer.BusinessLogo + "','" + payer.ImageMimeType + "','" + payer.ImageMimeType2+ "')");
cmd.Connection = con;
try
{
con.Open();
cmd.ExecuteNonQuery();
con.Close();
return "Success";
}
catch (Exception es)
{
throw es;
}
谢谢
Thank you
推荐答案
尝试执行使用参数查询
Try to Execute Query with parameter
// Assuming "conn" is an open SqlConnection
using(SqlCommand cmd = new SqlCommand("INSERT INTO mssqltable(varbinarycolumn) VALUES (@binaryValue)", conn))
{
// Replace 8000, below, with the correct size of the field
cmd.Parameters.Add("@binaryValue", SqlDbType.VarBinary, 8000).Value = arraytoinsert;
cmd.ExecuteNonQuery();
}
这篇关于我有这个问题,插入图像到我的数据库可以有人帮忙吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文