关于ADODB.Recordset 中open方法使用

尊马夏客 2013-03-07 03:37:11
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using System.Data.OracleClient;
using System.Configuration;
using System.Data.Common;
using ADODB;

namespace DLFlo.DBUtility
{
public static object GetSingle(string SQLString, ADODB.Connection objCn)
{
try
{
ADODB.Recordset rs = new ADODB.Recordset();
rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
rs.CursorType = ADODB.CursorTypeEnum.adOpenStatic;
rs.LockType = ADODB.LockTypeEnum.adLockBatchOptimistic;
rs.Open(SQLString, objCn);//报这里的open方法没有采用2个参数的重载
rs.ActiveConnection = null;
object obj = rs.Fields[0].OriginalValue;
rs.Close();
rs = null;

return obj;
}
catch (System.SystemException e)
{
throw e;
}
}
}
...全文
486 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
尊马夏客 2013-03-08
  • 打赏
  • 举报
回复
try
            {
                ADODB.Recordset rs = new ADODB.Recordset();
                rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
                rs.CursorType = ADODB.CursorTypeEnum.adOpenStatic;
                rs.LockType = ADODB.LockTypeEnum.adLockReadOnly;
                rs.Open(SQLString, objCn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockReadOnly, (int)ADODB.CommandTypeEnum.adCmdUnknown);
                rs.ActiveConnection = null;
                object obj = rs.Fields[0].OriginalValue;
                rs.Close();
                rs = null;

                return obj;
            }
            catch (System.SystemException e)这里抛出异常:在对应所需名称或序数的集合中,未找到项目。
            {
                throw e;
            }
尊马夏客 2013-03-07
  • 打赏
  • 举报
回复
尊马夏客 2013-03-07
  • 打赏
  • 举报
回复
但是我的系统就报错 引用的空间还有组件都和原系统一样。
gxingmin 2013-03-07
  • 打赏
  • 举报
回复
后面还有三个参数,你可以看看这些参数说明 http://blog.csdn.net/ivbapplication/article/details/2996214
尊马夏客 2013-03-07
  • 打赏
  • 举报
回复
这段使用代码是我从原系统拷过来的,我打开原系统就没有报错 原来就这么用的
gxingmin 2013-03-07
  • 打赏
  • 举报
回复
为什么不用ado.net?这个更好用
gxingmin 2013-03-07
  • 打赏
  • 举报
回复
Open([Source],[ActiveConnection],[CursorType],[LockType],[Options]) 有5个参数,你只给2个肯定不行啊

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧