我是这样保存的
byte[] fileByte = null;
fileByte = new byte[files[0].ContentLength];
数据库里面是Image类型,现在我要读取出来
public byte [] WJL
{
get { return _wjl; }
set { _wjl = value; }
} //WJL = Convert.ToByte( dr["WJL"].ToString()); 这里应该怎么写啊?
byte[] fileByte = null;
fileByte = new byte[files[0].ContentLength];
数据库里面是Image类型,现在我要读取出来
public byte [] WJL
{
get { return _wjl; }
set { _wjl = value; }
} //WJL = Convert.ToByte( dr["WJL"].ToString()); 这里应该怎么写啊?
解决方案 »
- 对路径“c:\windows\system32\inetsrv\201203161002528289_2.rar”的访问被拒绝。求解
- VB.NET 转成 asp.net 各位拜托了.
- 如何在客户端操作服务端的TextBox控件??
- asp.net3.5(C#)连接SQL2005数据库问题
- 如何将html输出的效果保存成图片?
- 新手上路:关于在datagird中自定义分页功能
- 各位大哥,帮忙看小弟这段代码有什么问题,俺是真的菜鸟!
- 我用winform写了一个 多选控件的问题
- asp.net openoffice x64问题
- 今天老板说,政府今年动作很大,微软的操作系统和软件都被撤掉了,要我们转linux和Java.怎么办?
- [求助]ASP.NETMVC3+EntityFramework4.1+MySQL配置文件问题?
- 注册页面判断用户是否存在
{
string id = Request.Params["Id"];
DataSet ds = service.getimage(id);
if (ds.Tables[0].Rows.Count == 0)
return;
byte[] bydata = (byte[])ds.Tables[0].Rows[0][0]; Response.ClearContent();
Response.ContentType = "image/jpeg";
Response.BinaryWrite(bydata);
}
/// 从数据库读取相应图片
/// </summary>
/// <param name="name">图片名称</param>
/// <returns>返回该图片</returns>
public static Image GetImage(string name)
{
SqlConnection con = new SqlConnection(SqlConString);
SqlCommand cmd = con.CreateCommand();
SqlParameter pname = new SqlParameter("@name", name);
cmd.Parameters.Add(pname);
cmd.CommandText = "select image from MyTable where name=@name";
con.Open();
byte[] MyData = (byte[])cmd.ExecuteScalar();
MemoryStream ms = new MemoryStream(MyData, 0, MyData.Length);
ms.Seek(0, SeekOrigin.Begin);
Image image = Image.FromStream(ms);
con.Close();
return image;
}
fileByte = new byte[files[0].ContentLength];
privateAch.WJL = fileByte;
FileInfo fi = new FileInfo(file.FileName.ToString());我这样写的,保存到数据库里的的值是"0x0后面全是0"这样的值是对的吗?现在我下载后文件报错说”损坏“
byte[] data=system.io.file.read();
fileByte = new byte[files[0].ContentLength];
另外数据库中这个字段是image类型,那就说明要把文件存到数据库吧,
1.你是要把文件存到数据库,还是文件名?
2.上边的这点代码如果是把文件存到数据库,第一步数组初始化没有问题,但是这个字节数据没有赋值