不允许从数据类型 nvarchar 到 varbinary 的隐式转换。请使用 CONVERT 函数来运行此查询。谢谢!
错误提示如图(图上部分是错误提示,下部分是数据表),以下是部分代码…………#region把文件上传至SQL数据库中//获取数据stringgetname=this.Tex...
错误提示如图(图上部分是错误提示,下部分是数据表),以下是部分代码
……
……
#region 把文件上传至SQL数据库中
//获取数据
string getname = this.TextBox1.Text;
string getfile = FileUpload1.PostedFile.FileName;
//上传文件
string getlastpath = this.FileUploadCompant(this.FileUpload1);
//获取上传文件流
byte[] getbyte = new byte[FileUpload1.PostedFile.ContentLength];
Stream filestream = this.FileUpload1.PostedFile.InputStream;
filestream.Read(getbyte, 0, FileUpload1.PostedFile.ContentLength);
string sql = "insert into StoreImage(markname,markContent,markType,markSize,markLinkUrl) values(@name,@content,@type,@size,@link)";
SqlParameter[] getpars = new SqlParameter[5];
getpars[0] = new SqlParameter("@name", getname);
getpars[1] = new SqlParameter("@content", getbyte);//文件内容插入This.Fileupload1.FileBytes同样可以直接转换成Byte数组不用转换
getpars[2] = new SqlParameter("@type", this.FileUpload1.PostedFile.ContentType);//保存文件类型
getpars[3] = new SqlParameter("@size", this.FileUpload1.PostedFile.ContentLength);//文件长度
getpars[4] = new SqlParameter("@link", getlastpath);
int getrescount = SqlHelper.ExecuteNonQuery(SqlHelper.connString, CommandType.Text, sql, getpars);
……
……
public static int ExecuteNonQuery(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
{
if (connection == null) throw new ArgumentNullException("connection");
// Create a command and prepare it for execution
SqlCommand cmd = new SqlCommand();
bool mustCloseConnection = false;
PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters, out mustCloseConnection);
// Finally, execute the command
int retval = cmd.ExecuteNonQuery();
// Detach the SqlParameters from the command object, so they can be used again
cmd.Parameters.Clear();
if (mustCloseConnection)
connection.Close();
return retval;
}
……
…… 展开
……
……
#region 把文件上传至SQL数据库中
//获取数据
string getname = this.TextBox1.Text;
string getfile = FileUpload1.PostedFile.FileName;
//上传文件
string getlastpath = this.FileUploadCompant(this.FileUpload1);
//获取上传文件流
byte[] getbyte = new byte[FileUpload1.PostedFile.ContentLength];
Stream filestream = this.FileUpload1.PostedFile.InputStream;
filestream.Read(getbyte, 0, FileUpload1.PostedFile.ContentLength);
string sql = "insert into StoreImage(markname,markContent,markType,markSize,markLinkUrl) values(@name,@content,@type,@size,@link)";
SqlParameter[] getpars = new SqlParameter[5];
getpars[0] = new SqlParameter("@name", getname);
getpars[1] = new SqlParameter("@content", getbyte);//文件内容插入This.Fileupload1.FileBytes同样可以直接转换成Byte数组不用转换
getpars[2] = new SqlParameter("@type", this.FileUpload1.PostedFile.ContentType);//保存文件类型
getpars[3] = new SqlParameter("@size", this.FileUpload1.PostedFile.ContentLength);//文件长度
getpars[4] = new SqlParameter("@link", getlastpath);
int getrescount = SqlHelper.ExecuteNonQuery(SqlHelper.connString, CommandType.Text, sql, getpars);
……
……
public static int ExecuteNonQuery(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
{
if (connection == null) throw new ArgumentNullException("connection");
// Create a command and prepare it for execution
SqlCommand cmd = new SqlCommand();
bool mustCloseConnection = false;
PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters, out mustCloseConnection);
// Finally, execute the command
int retval = cmd.ExecuteNonQuery();
// Detach the SqlParameters from the command object, so they can be used again
cmd.Parameters.Clear();
if (mustCloseConnection)
connection.Close();
return retval;
}
……
…… 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询