请帮助-无法更新Mysql DB中的图像 [英] Pls help- Not able to update image in Mysql DB
本文介绍了请帮助-无法更新Mysql DB中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好朋友,以下帮助是为更新徽标图像而编写的代码,此代码未收到任何错误,但是当我查看数据库时,列值仅显示(排除)...(数据类型为longBlob)
请提示问题出在哪里.
Hi friends pls help below is code am writing for update a logo image this code is not getting any error but when i look in to database the column value is showing (Excluded) only...(datatype is longBlob)
pls suggest where is the problem.
protected void imgBtnSave_Click(object sender, ImageClickEventArgs e)
{
if (LogoUpload.PostedFile != null && !string.IsNullOrEmpty(LogoUpload.PostedFile.FileName))
{
byte[] imageSize = new byte[LogoUpload.PostedFile.ContentLength];
HttpPostedFile uploadedImage__1 = LogoUpload.PostedFile;
uploadedImage__1.InputStream.Read(imageSize, 0, Convert.ToInt32(LogoUpload.PostedFile.ContentLength));
cmd = new MySqlCommand ();
cmd.CommandText = "UPDATE schoolbook.t_school_master SET tsm_sch_logo=@Image where tsm_sch_code=''SCH00001''";
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
MySqlParameter UploadedImage__2 = new MySqlParameter("@Image", MySqlDbType.LongBlob);
UploadedImage__2.Value = imageSize;
UploadedImage__2.Size = imageSize.Length;
cmd.Parameters.Add(UploadedImage__2);
con.Open();
Int32 result=0;
result += cmd.ExecuteNonQuery();
con.Close();
}
else
{
Response.Write("<script>alert(''Browse Logo First'');</script>");
return;
//*****End if Picture Browse...
}
Response.Redirect("AboutSchoolEntry.aspx");
}
推荐答案
首先创建一个包含数据类型为image的image_content列的表,并在上载按钮click事件中添加以下代码.
如果(FileUpload1.PostedFile!= null
&& FileUpload1.PostedFile.FileName!=")
{
byte [] myimage =新的byte [FileUpload1.PostedFile.ContentLength];
HttpPostedFile图片= FileUpload1.PostedFile;
Image.InputStream.Read(myimage,0,
(int)FileUpload1.PostedFile.ContentLength);
SqlConnection myConnection =
新的SqlConnection(数据源= ComputerName \\ SQLEXPRESS;
初始目录= dbname;集成安全性= SSPI);
SqlCommand storeimage =
新的SqlCommand("INSERT INTO Image_Gallery"
+(Img_Id,Image_Content,Image_Type,Image_Size)"
+值(3,@ image,@ imagetype,@ imagesize)"
,myConnection);
storeimage.Parameters.Add("@ image",
SqlDbType.Image,myimage.Length).Value = myimage;
storeimage.Parameters.Add("@ imagetype",
SqlDbType.VarChar,100).值
= FileUpload1.PostedFile.ContentType;
storeimage.Parameters.Add("@ imagesize",
SqlDbType.BigInt,99999).值
= FileUpload1.PostedFile.ContentLength;
myConnection.Open();
storeimage.ExecuteNonQuery();
myConnection.Close();
Respone.Write(成功上传图片");
}
谢谢!!
Hi,
First create a table which contain image_content column of datatype image and add the following code in upload button click event.
if (FileUpload1.PostedFile != null
&& FileUpload1.PostedFile.FileName != "")
{
byte[] myimage = new byte[FileUpload1.PostedFile.ContentLength];
HttpPostedFile Image = FileUpload1.PostedFile;
Image.InputStream.Read(myimage, 0,
(int)FileUpload1.PostedFile.ContentLength);
SqlConnection myConnection =
new SqlConnection("Data Source = ComputerName\\SQLEXPRESS;
Initial Catalog= dbname; Integrated Security= SSPI");
SqlCommand storeimage =
new SqlCommand("INSERT INTO Image_Gallery "
+"(Img_Id, Image_Content, Image_Type, Image_Size) "
+" values (3, @image, @imagetype, @imagesize)"
, myConnection);
storeimage.Parameters.Add("@image",
SqlDbType.Image, myimage.Length).Value = myimage;
storeimage.Parameters.Add("@imagetype",
SqlDbType.VarChar, 100).Value
= FileUpload1.PostedFile.ContentType;
storeimage.Parameters.Add("@imagesize",
SqlDbType.BigInt, 99999).Value
= FileUpload1.PostedFile.ContentLength;
myConnection.Open();
storeimage.ExecuteNonQuery();
myConnection.Close();
Respone.Write("successfully upload the image");
}
Thanks!!.
这篇关于请帮助-无法更新Mysql DB中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文