一个关于 Find函数的问题?

xymeng24 2006-04-09 08:54:46
我用下面这条语句总是出错:
m_pRecordset->Find ("Place='struct_DisStor.Place'",0,adSearchForward,"");
struct_DisStor是我定义的一个结构体,Place为BYTE类型.
换成:m_pRecordset->Find ("Place=BYTE(struct_DisStor.Place)",0,adSearchForward,"");
也不行,调试时显示BYTE(struct_DisStor.Place)的内容是正确的.
而m_pRecordset->Find ("Place='2'",0,adSearchForward,""); 就可以了,请问这是为什么呀?怎么解决这个问题?
...全文
449 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xymeng24 2006-04-10
  • 打赏
  • 举报
回复
为什么接收到日期型数据和浮点型数据存入数据库的值和原来的不一样?
_variant_t v1,v2;
v1=( short)struct_DisStor.Speed;
v2=struct_DisStor.Datetime;

m_pRecordset->PutCollect("Speed",v1);
m_pRecordset->PutCollect("Datetime",v2);
xymeng24 2006-04-10
  • 打赏
  • 举报
回复
为什么接收到日期型数据和浮点型数据存入数据库的值和原来的不一样?
_variant_t v1,v2;
v1=( short)struct_DisStor.Speed;
v2=struct_DisStor.Datetime;

m_pRecordset->PutCollect("Speed",v1);
m_pRecordset->PutCollect("Datetime",v2);
菜牛 2006-04-10
  • 打赏
  • 举报
回复
CString strFind;
strFind.Format("Place='%d'", struct_DisStor.Place);
m_pRecordset->Find(strFind, 0,adSearchForward,"");
xymeng24 2006-04-10
  • 打赏
  • 举报
回复
有没有具体的解决方法呀?
sakaer 2006-04-09
  • 打赏
  • 举报
回复
Find
This method returns a recordset that matches specified search criteria.

recordset.Find(criteria, [skipRows], [searchDirection], [start]) As Recordset
Parameters
criteria
Required. String that contains a statement that specifies the column name, comparison operator, and value to use in the search.
skipRows
Optional. Long value that specifies the offset from the current row or start parameter bookmark to begin the search.
searchDirection
Optional. Long value that specifies the direction to search in a recordset. The following table shows the constants and their values that can be used with the searchDirection parameter. Constant Value Description
adSearchForward 1 Searches forward. Search stops at end of a recordset. If a match is not found, the record pointer is positioned at EOF.
adSearchBackward -1 Searches backward. Search stops at beginning of a recordset. If a match is not found, the record pointer is positioned at BOF.


start
Optional. A Variant bookmark that functions as the starting position for the search.
Return Values
Returns a Recordset object

Remarks
The comparison operator in criteria may be ">" (greater than), "<" (less than), "=" (equal), ">=" (greater than or equal), "<=" (less than or equal), "<>" (not equal), or LIKE (pattern matching).

If the comparison operator used is LIKE, the string value may contain an asterisk (*) to find one or more occurrences of any character or substring. For example, "state LIKE 'M*'" matches Maine and Massachusetts.

The value in criteria may be a string, floating point number, or date. String values are delimited with single quotes or "#" (number sign) marks (for example, "state = 'WA'" or "state = #WA#"). Date values are delimited with "#" (number sign) marks (for example, "start_date > #7/22/97#").

Examples
The following code example shows how to search for a recordset using the Find method.

Dim cn, rs, strConn
Set cn = CreateObject("adoce.connection.3.1")
Set rs = CreateObject("adoce.recordset.3.1")

strConn = "Provider=SQLOLEDB;Data Source=DATBTEST;Initial Catalog=TEST;User Id=sa;Password=;"
cn.Open strConn

rs.Open "employees", strConn, 1, adLockOptimistic
rs.Find "BirthDate = #7/2/63#"

'Insert code here to display the returned recordset.

rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
上面是msdn的解释。。。。
你直接在这里用'struct_DisStor.Place'好象是不行的。

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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