无法更新表格中的图像 [英] unable to update an image in a table

查看:43
本文介绍了无法更新表格中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我无法更新名为PictureFile的''image''数据类型列。



以下是我的代码:

string fileName = ImagePreview.ImageUrl;

int fileLength = PhotoUpload。 PostedFile.ContentLength;

int v_mem_id = 158;

byte [] imageBytes = new byte [fileLength];

PhotoUpload.PostedFile.InputStream。读取(imageBytes,0,fileLength);

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings [tnrestConnectionString]。ConnectionString);

尝试

{

string updateSql =UPDATE member+SET PictureFile = @ a,pictureFile WHERE mem_id =+ v_mem_id +;

SqlCommand UpdateCmd = new SqlCommand (updateSql,conn);

UpdateCmd.Parameters.Add(@ a,SqlDbType.Image,10,PictureFile);

UpdateCmd.Parameters [@ a。。Value = Convert.ToByte(fileLength).ToString();



conn.Open();

UpdateCmd.ExecuteNonQuery();

}

catch(SqlException ex)

{

}



任何人都可以帮帮我。

解决方案

我想你忘了分配imageBytes = PhotoUpload.FileBytes; ...在代码中添加以下部分

  byte  [] imageBytes =  new   byte  [fileLength]; 
imageBytes = PhotoUpload.FileBytes;


我认为这会有所帮助。



替换以下所有代码



  string  fileName = ImagePreview.ImageUrl ; 
int fileLength = PhotoUpload.PostedFile.ContentLength;
int v_mem_id = 158 ;
byte [] imageBytes = new byte < /跨度> [文件长度];
PhotoUpload.PostedFile.InputStream.Read(imageBytes, 0 ,fileLength);





使用此代码

  string  fileName = ImagePreview.ImageUrl; 
byte [] imageBytes = File.ReadAllBytes(fileName);
UpdateCmd.Parameters.AddWithValue( @ a,imageBytes);


In my project I am unable to update an ''image'' datatype column named as ''PictureFile''.

The following is my code:
string fileName = ImagePreview.ImageUrl;
int fileLength = PhotoUpload.PostedFile.ContentLength;
int v_mem_id = 158;
byte[] imageBytes = new byte[fileLength];
PhotoUpload.PostedFile.InputStream.Read(imageBytes, 0, fileLength);
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["tnrestConnectionString"].ConnectionString);
try
{
string updateSql = "UPDATE member " + "SET PictureFile = @a,pictureFile WHERE mem_id= " + v_mem_id + " ";
SqlCommand UpdateCmd = new SqlCommand(updateSql, conn);
UpdateCmd.Parameters.Add("@a", SqlDbType.Image,10, "PictureFile");
UpdateCmd.Parameters["@a"].Value = Convert.ToByte(fileLength).ToString();

conn.Open();
UpdateCmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
}

Can anyone help me out.

解决方案

i think u forgot to assign imageBytes = PhotoUpload.FileBytes; ...add following section in code

byte[] imageBytes = new byte[fileLength];
imageBytes = PhotoUpload.FileBytes;


I think this will be helpful.

Replace all the below code

string fileName = ImagePreview.ImageUrl;
int fileLength = PhotoUpload.PostedFile.ContentLength;
int v_mem_id = 158;
byte[] imageBytes = new byte[fileLength];
PhotoUpload.PostedFile.InputStream.Read(imageBytes, 0, fileLength);



with this code

string fileName = ImagePreview.ImageUrl;
byte[] imageBytes = File.ReadAllBytes(fileName);
UpdateCmd.Parameters.AddWithValue("@a",imageBytes);


这篇关于无法更新表格中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆