1。Web如何上传文件,如图像文件;
2.如何将图像文件放到BLOB字段中;
2.如何将图像文件放到BLOB字段中;
解决方案 »
- 怎么把数据库中的一张数据表中的图片字段里的2进制转换成图片放到picturebox里?
- [[[未能找到任何可识别的数字]]]
- 请注释一下执行过程
- 一样的程序为什么别的机子能运行成功,我的却不能。
- C#与数据库连接的一个问题?
- 問題得不到解決只有 100 高分出擊了!!
- c#文本框限制的问题
- 在将 nvarchar 值 '4951,4952,4953,4954,4955,4956' 转换成数据类型 int 时失败。
- C# 如何将一个Treeview的树形结构保存成文件并可以再反读
- 为了不让<<Visual C#.Net 核心网络核心编程>> 误导大家对异步Socket编程的理解,我将我得源代码贴出,大家请帮测试.(5)
- 在DAL层如何传参数给存储过程执行后返回存储过程的输出参数?
- arraylist深度复制的问题
Byte[] FileByteArray = new Byte[FileLength];
Stream StreamObject = UpFile.InputStream;
StreamObject.Read(FileByteArray,0,FileLength);
SqlConnection sqlConnection1 = new SqlConnection();
sqlConnection1.ConnectionString="";
+" VALUES (@name,@guidang, @Image, @ContentType, @ImageSize)";
SqlCommand sqlCommand1 = new SqlCommand(sqlstr, sqlConnection1);
string aa=UpFile.FileName;
string[] ss=aa.Split('\\');
string dd=ss[ss.Length-1].Trim().ToString();
sqlCommand1.Parameters.Add("@guidang",SqlDbType.Int,8).Value=0;
sqlCommand1.Parameters.Add("@Image",SqlDbType.Binary, FileLength).Value = FileByteArray;
sqlCommand1.Parameters.Add("@name" ,SqlDbType.VarChar, 100).Value=dd;
sqlCommand1.Parameters.Add("@ContentType",SqlDbType.VarChar,50).Value=File.ContentType;
sqlCommand1.Parameters.Add("@ImageSize", SqlDbType.BigInt,8).Value = File.ContentLength;
sqlConnection1.Open();
sqlCommand1.ExecuteNonQuery();
sqlConnection1.Close();
要给分啊!!!
如有不明白的可以msn:[email protected] 来探讨
if(this.File1.Value!=""||this.File1.Value!=null)
{
try
{
HttpPostedFile UpFile = this.File1.PostedFile;
FileLength = UpFile.ContentLength;
if (FileLength != 0)
{
Byte[] FileByteArray = new Byte[FileLength];
Stream StreamObject = UpFile.InputStream;
StreamObject.Read(FileByteArray,0,FileLength);
dr["c_image"]=FileByteArray; }
}
catch
{
Response.Write("<script defer>alert(\"图片格式不正确!\")</script>");
return;
}
}
读取:try
{
byte[] bys = (byte[])row["c_image"];
if(bys.Length > 100)
Response.OutputStream.Write(bys, 0, bys.Length);
Response.Write("没有图片!");
}
catch
{
Response.Write("没有图片!");
return;
}
{
try
{
HttpPostedFile UpFile = this.File1.PostedFile;
FileLength = UpFile.ContentLength;
if (FileLength != 0)
{
Byte[] FileByteArray = new Byte[FileLength];
Stream StreamObject = UpFile.InputStream;
StreamObject.Read(FileByteArray,0,FileLength);
dr["c_image"]=FileByteArray; }
}
catch
{
Response.Write("<script defer>alert(\"图片格式不正确!\")</script>");
return;
}
}
读取:try
{
byte[] bys = (byte[])row["c_image"];
if(bys.Length > 100)
Response.OutputStream.Write(bys, 0, bys.Length);
Response.Write("没有图片!");
}
catch
{
Response.Write("没有图片!");
return;
}
Image image =Image.FormStream(new MemoryStream(bys));
Image pThumbnail = image.GetThumbnailImage(100, 100, null, new IntPtr());
可以把他放在可以控制大小的容器里(如pinvel)控制容器大小是可以的