无法更新表格中的图像 [英] unable to update an image in a table
问题描述
在我的项目中,我无法更新名为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屋!