我用一个.ashx页面转换二进制数据流(blob),提示:值不能为空,参数名string。 代码如下:
using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using com.pub;
using System.Text;namespace com.lis.aspx.Documen
{
/// <summary>
/// $codebehindclassname$ 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class GetAttatch1 : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
SQLBase sb = new SQLBase();
string sql = "";
DataTable table;
DBParameterCollection pmList = new DBParameterCollection();
pmList.Add(DBParameter.CreateIntParameter("ID", int.Parse(context.Request.QueryString["ID"])));
byte[] bb;
if (string.Compare("InlineView", context.Request.QueryString["Action"]) == 0)
{
sql = @"select FileName, FileExt, ORGCONTENT from DOC_MAINDOCUMENTS where ID = :ID";
table = sb.ExecuteDataTable(sql, pmList); if (table.Rows.Count <= 0)
{
context.Response.ContentType = "text/plain";
bb = Encoding.GetEncoding("GB2312").GetBytes("没有内容!");
}
else
{
string s1 = table.Rows[0]["FileExt"].ToString().ToLower();
string s = table.Rows[0]["FileName"].ToString() + s1;
if (s1 != "")
s1 = s1.Substring(1);
bb = (byte[])table.Rows[0]["ORGCONTENT"];
if ("txt" == s1)
{
context.Response.ContentType = "text/html";
s = table.Rows[0]["FileName"].ToString() + ".html";
string cc = Encoding.GetEncoding("GB2312").GetString(bb);
if (cc != null)
{
cc = cc.Replace("\r\n", "<br>");
cc = cc.Replace(" ", " ");
}
bb = Encoding.GetEncoding("GB2312").GetBytes(cc);
}
else if ("doc" == s1 || "dot" == s1 || "rtf" == s1 || "docx" == s1 || "wps" == s1)
{
context.Response.ContentType = "text/mhtml";
s = table.Rows[0]["FileName"].ToString() + ".mht";
}
else if ("pdf" == s1)
context.Response.ContentType = "application/pdf";
else if ("xls" == s1)
context.Response.ContentType = "application/vnd.ms-excel";
else if ("jpeg" == s1 || ".jpg" == s1)
context.Response.ContentType = "image/jpeg";
else if ("gif" == s1)
context.Response.ContentType = "image/gif";
else
context.Response.ContentType = "application/octet-stream";
context.Response.AppendHeader("Content-Disposition",
"inline;filename=" + HttpUtility.UrlEncode(s) + ";filetype=" + s1);
}
}
else
{
sql = @"select FileName, FileExt, ORGCONTENT from DOC_MAINDOCUMENTS where ID = :ID";
table = sb.ExecuteDataTable(sql, pmList); string ss = table.Rows[0]["FileName"].ToString() + table.Rows[0]["FileExt"].ToString().ToLower();
bb = (byte[])table.Rows[0]["ORGCONTENT"];
context.Response.ContentType = "application/octet-stream";
context.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(ss));
} if (bb == null || bb.Length <= 0)
{
bb = Encoding.GetEncoding("GB2312").GetBytes("没有内容!");
} context.Response.OutputStream.Write(bb, 0, bb.Length);
} public bool IsReusable
{
get
{
return false;
}
}
}
}
请各位高手帮我看看那里有错,在线等解决··
using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using com.pub;
using System.Text;namespace com.lis.aspx.Documen
{
/// <summary>
/// $codebehindclassname$ 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class GetAttatch1 : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
SQLBase sb = new SQLBase();
string sql = "";
DataTable table;
DBParameterCollection pmList = new DBParameterCollection();
pmList.Add(DBParameter.CreateIntParameter("ID", int.Parse(context.Request.QueryString["ID"])));
byte[] bb;
if (string.Compare("InlineView", context.Request.QueryString["Action"]) == 0)
{
sql = @"select FileName, FileExt, ORGCONTENT from DOC_MAINDOCUMENTS where ID = :ID";
table = sb.ExecuteDataTable(sql, pmList); if (table.Rows.Count <= 0)
{
context.Response.ContentType = "text/plain";
bb = Encoding.GetEncoding("GB2312").GetBytes("没有内容!");
}
else
{
string s1 = table.Rows[0]["FileExt"].ToString().ToLower();
string s = table.Rows[0]["FileName"].ToString() + s1;
if (s1 != "")
s1 = s1.Substring(1);
bb = (byte[])table.Rows[0]["ORGCONTENT"];
if ("txt" == s1)
{
context.Response.ContentType = "text/html";
s = table.Rows[0]["FileName"].ToString() + ".html";
string cc = Encoding.GetEncoding("GB2312").GetString(bb);
if (cc != null)
{
cc = cc.Replace("\r\n", "<br>");
cc = cc.Replace(" ", " ");
}
bb = Encoding.GetEncoding("GB2312").GetBytes(cc);
}
else if ("doc" == s1 || "dot" == s1 || "rtf" == s1 || "docx" == s1 || "wps" == s1)
{
context.Response.ContentType = "text/mhtml";
s = table.Rows[0]["FileName"].ToString() + ".mht";
}
else if ("pdf" == s1)
context.Response.ContentType = "application/pdf";
else if ("xls" == s1)
context.Response.ContentType = "application/vnd.ms-excel";
else if ("jpeg" == s1 || ".jpg" == s1)
context.Response.ContentType = "image/jpeg";
else if ("gif" == s1)
context.Response.ContentType = "image/gif";
else
context.Response.ContentType = "application/octet-stream";
context.Response.AppendHeader("Content-Disposition",
"inline;filename=" + HttpUtility.UrlEncode(s) + ";filetype=" + s1);
}
}
else
{
sql = @"select FileName, FileExt, ORGCONTENT from DOC_MAINDOCUMENTS where ID = :ID";
table = sb.ExecuteDataTable(sql, pmList); string ss = table.Rows[0]["FileName"].ToString() + table.Rows[0]["FileExt"].ToString().ToLower();
bb = (byte[])table.Rows[0]["ORGCONTENT"];
context.Response.ContentType = "application/octet-stream";
context.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(ss));
} if (bb == null || bb.Length <= 0)
{
bb = Encoding.GetEncoding("GB2312").GetBytes("没有内容!");
} context.Response.OutputStream.Write(bb, 0, bb.Length);
} public bool IsReusable
{
get
{
return false;
}
}
}
}
请各位高手帮我看看那里有错,在线等解决··
我用的是oracle数据库,blob是二进制数据流,应该和sqlserver里面的image差不多吧。
错误是提示在 pmList.Add(DBParameter.CreateIntParameter("ID", int.Parse(context.Request.QueryString["ID"])));这一行···
http://www.cnblogs.com/zhengmaoch/archive/2005/08/10/212014.html而且好像BLOB只能存数据流,我也不知道理解的对不对,贴给你。
blob:二进制lob,为二进制数据,最长可达4GB,存贮在数据库中。
clob:字符lob,字符数据,最长可以达到4GB,存贮在数据库中。
bfile:二进制文件;存贮在数据库之外的只读型二进制数据,最大长度由操作系统限制。
nclob:支持对字节字符集合(nultibyte characterset)的一个clob列
string cnnstr = "provider=oraoledb.oracle;data source=yourdb;user id=xxxx;password=xxxx;";
oledbconnection con = new oledbconnection(cnnstr);
try
{
con.open();
}
catch
{}
oledbcommand cmd = new oledbcommand(cnnstr,con);