asp.net 中 使用 ado 的 Recordset GetString 函数 By shawl.qiu

asp.net 中 使用 ado 的 Recordset GetString 函数 By shawl.qiu

keyword: using ado in .net

说明:
 这个问题本来不想写个博的, 不过有鉴于这个功能非常不错, 也确实费了我一两小时, 就总结一下啰. 

 Ado GetString 这个方法在使用 ASP 时屡用不爽呀,
不过跑到 Ado.net, 居然发现没这个功能...

到论坛发帖也请教不出个所以然, 最后放狗搜, 发现N多老外也很奇怪没这个功能, 那些 MVP 的解释是: ado.net 不是 ado, 因此某些方法没有不足为奇...

最后还是记得某时看 MSDN 时, 知道可以使用 .NET 调用 COM 方法,
然后就自然的使用 COM 方法解决了.

目录:
1. 编译 com
2. 在 .aspx 页中使用(至于编译引用什么的, 自己看着办)
3. 补充一下, web.config 内容, 请按需要修改

shawl.qiu
2007-03-04
http://blog.csdn.net/btbtd

内容:

1. 编译 com
以下操作按你自己的具体路径:
从命令行切换到目录:
H:/WINDOWS/Microsoft.NET/Framework/v1.1.4322/Bin
编译:
TlbImp "H:/Program Files/Common Files/System/ado/msado15.dll" /out:ADODB.dll
... 晕,  bin 知道是什么吧, 那就拷贝呀...

2. 在 .aspx 页中使用(至于编译引用什么的, 自己看着办):
  1. <%@ Page Language="C#AutoEventWireup="True" %>
  2. <%@ Assembly Name="ADODB" %><%@ import Namespace="ADODB" %>
  3. <script runat="server">
  4.  
  5.  string SqlCnnOleDb = ConfigurationSettings.AppSettings["SqlCnnOleDb"]+"";
  6.  string SqlQryStr = "select * from allCat order by cat1id, cat2id, cat3id asc";
  7.  
  8.  void Page_Load(Object s, EventArgs e)
  9.  {
  10.   HttpContext.Current.Response.Write
  11.   (
  12.    Adodb.GetStringRs(SqlQryStr, SqlCnnOleDb, -1, "##", "##@", "null")
  13.   );
  14.  } // end Page_Load
  15.  
  16. /*-----------------------------------------------------------------------------------*/
  17.  * shawl.qiu c# Adodb class v1.0
  18. /*-----------------------------------------------------------------------------------*/
  19. //---------------------------------------------------------------------begin class Adodb
  20. public class Adodb
  21. {
  22.  //-----------------------------------begin event
  23.  public Adodb()
  24.  {
  25.  }
  26.  
  27.  ~Adodb()
  28.  {
  29.  }
  30.  //-----------------------------------end event
  31.  
  32.  //-----------------------------------begin public constant
  33.  //-----------------------begin about
  34.  public const String auSubject = "shawl.qiu c# Adodb class";
  35.  public const String auVersion = "v1.0";
  36.  public const String au = "shawl.qiu";
  37.  public const String auEmail = "shawl.qiu@gmail.com";
  38.  public const String auBlog = "http://blog.csdn.net/btbtd";
  39.  public const String auCreateDate = "2007-3-3";
  40.  //-----------------------end about
  41.  //-----------------------------------end public constant
  42.  
  43.  //-----------------------------------begin private constant
  44.  //-----------------------------------end private constant
  45.  
  46.  //-----------------------------------begin public static method
  47.  public static string GetStringRs
  48.   (
  49.    CursorTypeEnum ctEnum,
  50.    LockTypeEnum enumLt,
  51.    string SqlQryStr, 
  52.    string SqlCnnOleDb, 
  53.    int NumRows,
  54.    string ColumnDelimeter,
  55.    string RowDelimeter,
  56.    string NullExpr
  57.   )
  58.  {
  59.   string result = "";
  60.    
  61.   Recordset rs = new Recordset();
  62.   
  63.    rs.Open
  64.    (
  65.     SqlQryStr,
  66.     SqlCnnOleDb,
  67.     ctEnum, 
  68.     enumLt,
  69.     -1
  70.    );
  71.    
  72.    result = 
  73.     rs.GetString
  74.     (
  75.      StringFormatEnum.adClipString,
  76.      NumRows,
  77.      ColumnDelimeter,
  78.      RowDelimeter,
  79.      NullExpr
  80.     );
  81.    
  82.    rs.Close();
  83.    rs=null;
  84.    
  85.   return result;
  86.  } // end public static string GetStringRs
  87.  
  88.  public static string GetStringRs
  89.   (
  90.    string SqlQryStr, 
  91.    string SqlCnnOleDb, 
  92.    int NumRows,
  93.    string ColumnDelimeter,
  94.    string RowDelimeter,
  95.    string NullExpr
  96.   )
  97.  {
  98.   return 
  99.   GetStringRs
  100.    (
  101.     CursorTypeEnum.adOpenKeyset,
  102.     LockTypeEnum.adLockOptimistic,
  103.     SqlQryStr, 
  104.     SqlCnnOleDb, 
  105.     NumRows,
  106.     ColumnDelimeter,
  107.     RowDelimeter,
  108.     NullExpr
  109.    );
  110.  } // end public static string GetStringRs
  111.  //-----------------------------------end public static method
  112. }
  113. //---------------------------------------------------------------------end class Adodb

  114. </script>
  115. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  116. <html xmlns="http://www.w3.org/1999/xhtml">
  117. <head>
  118. <meta http-equiv="Content-Typecontent="text/html; charset=utf-8" />
  119. <title>shawl.qiu template</title>
  120. </head>
  121. <body>
  122.  <form runat="server">

  123.  </form>
  124. </body>
  125. </html>



3. 补充一下, web.config 内容, 请按需要修改:
  1. <?xml version="1.0" encoding="UTF-8" ?> 
  2. <configuration>
  3.  
  4.  <appSettings>
  5.   <!--<add key="sq" value="just a test" />-->
  6.   <!--Response.Write(ConfigurationSettings.AppSettings["sq"]+""); -->

  7.   <add key="SqlCnn" value="
  8.    data source = 127.0.0.1;
  9.    user id = sqCsAtSysUser;
  10.    password = sqCsAtSysUserPwd;
  11.    persist security info = false;
  12.    initial catalog = sqCsAtSys
  13.    " />
  14.   <!-- string SqlCnn = ConfigurationSettings.AppSettings["SqlCnn"]+""; -->

  15.   <add key="SqlCnnOleDb" value="
  16.    provider=sqloledb;
  17.    data source=127.0.0.1;
  18.    user id=sqCsAtSysUser; 
  19.    password=sqCsAtSysUserPwd;
  20.    persist security info=false;
  21.    initial catalog=sqCsAtSys
  22.    " />
  23.   <!-- string SqlCnnOleDb = ConfigurationSettings.AppSettings["SqlCnnOleDb"]+""; -->

  24.  </appSettings>
  25.  
  26.  <system.web>
  27.   <httpRuntime maxRequestLength="20480"
  28.    useFullyQualifiedRedirectUrl="true"
  29.    executionTimeout="90"
  30.    />
  31.          
  32.  <customErrors defaultRedirect="/include/error/generalError.html"
  33.   mode="RemoteOnly" >
  34.   <error statusCode="404" redirect="/include/error/error404.html" />
  35.  </customErrors>
  36.  
  37.  <globalization 
  38.   requestEncoding="UTF-8"
  39.   responseEncoding="UTF-8"
  40.   fileEncoding="UTF-8"
  41.   />
  42.   
  43. <!--  <sessionState mode="InProc"
  44.    cookieless="false"
  45.    timeout="20" >
  46.   </sessionState>-->
  47.   
  48.  <sessionState mode="SQLServer"
  49.   cookieless="true"
  50.   timeout="20"
  51.   sqlConnectionString="data source=127.0.0.1;user id=sqCsAtSysUser;password=sqCsAtSysUserPwd"
  52.   >
  53.  </sessionState>
  54.  
  55.  <compilation defaultLanguage="c#"
  56.    debug="true"
  57.    numRecompilesBeforeAppRestart="15">
  58.    <assemblies>
  59.       <add assembly="ADODB"/>
  60.    </assemblies>
  61. </compilation>

  62.  </system.web>
  63.  
  64. </configuration>



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值