首页
社区
课程
招聘
[求助]C++ ADO连接数据库的问题
发表于: 2015-5-25 13:07 5169

[求助]C++ ADO连接数据库的问题

bxc 活跃值
6
2015-5-25 13:07
5169
在C++中,使用ADO连接数据库并查询结果集。
有个字段的类型应该是adDate,请问在C++中对应什么类型?
我是直接
_RecordsetPtr->Fields->GetItem(0)->GetValue()
来获取字段值的。
不知道adDate应该赋给什么类型的变量0.0

[课程]Linux pwn 探索篇!

收藏
免费 0
支持
分享
最新回复 (11)
雪    币: 3330
活跃值: (1662)
能力值: ( LV6,RANK:93 )
在线值:
发帖
回帖
粉丝
2
auto
com里一般是variant之类的吧
2015-5-25 13:10
0
雪    币: 16444
活跃值: (2463)
能力值: ( LV9,RANK:147 )
在线值:
发帖
回帖
粉丝
3
- -不懂, 把COM的都试一遍, BSTR

5楼的应该可以.楼主可以试下.
2015-5-25 13:31
0
雪    币: 7068
活跃值: (3517)
能力值: ( LV12,RANK:340 )
在线值:
发帖
回帖
粉丝
4
谢谢,那么如果我有6个DWORD,分别是年月日,时分秒。
怎么样把这个auto的变量拆分给这6个DWORD呢?
2015-5-25 14:14
0
雪    币: 5
活跃值: (256)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
5
试试 coledatetime.
2015-5-25 14:20
0
雪    币: 7068
活跃值: (3517)
能力值: ( LV12,RANK:340 )
在线值:
发帖
回帖
粉丝
6
BSTR是文本类型吧
2015-5-25 15:08
0
雪    币: 16444
活跃值: (2463)
能力值: ( LV9,RANK:147 )
在线值:
发帖
回帖
粉丝
7
对,你可以无视我.我只是帮你顶下贴的,.顺便也学习下.
2015-5-25 15:11
0
雪    币: 25
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8
由此看出,落后10年并不夸张。
http://microsoft.public.data.ado.narkive.com/CRofQlOX/cadorecordbinding-addate

浮点型的,float

DateTime is (educated guess) is using Excel's Dublin Julian
format.
See
http://en.wikipedia.org/wiki/Julian_day_number
and search for "Dublin" on web page

Whole numbers are the number of days.
Fractional numbers are the time out of a 24 hour day.
0.0 is 30/Dec/1899
1.0 is 31/Dec/1899
2.0 is 1/Jan/1900
3.0 is 2/Jan/1900
4.0 is 3/Jan/1900
and so on
0.0 is 00:00:00 on 24 hour clock
0.5 is 12:00:00 on 24 hour clock
0.25 is 06:00:00 on 24 hour clock
0.75 is 18:00:00 on 24 hour clock
0.10 is 02.24:00 on 24 hour clock
and so on.
2015-5-25 20:53
0
雪    币: 7068
活跃值: (3517)
能力值: ( LV12,RANK:340 )
在线值:
发帖
回帖
粉丝
9
3Q~,虽然有些看不懂~
2015-5-25 20:57
0
雪    币: 8
活跃值: (120)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
我在不确定长度的时候,都是CString字符串,这样就可以保证容纳了;后面在按照需要转换
2015-5-25 21:02
0
雪    币: 3330
活跃值: (1662)
能力值: ( LV6,RANK:93 )
在线值:
发帖
回帖
粉丝
11
我随便说的,哈哈
网上搜了下(关键词:"adDate" ado c++),有跟你需求相反的,可以参考下:
来自 http://www.databaseforum.info/2/22/52b1c2c388f82c80.html :
Visual Studio C++ >> How to use a unix timestamp for an adDate ADO Parameter in c++ without COleDateTime

Just thought I'd share this because it has been bugging me for
hours...

When you're calling a SQL Server stored procedure with a DATE
parameter, this is how you can add the parameter in ADO (without the
need for COleDateTime)....

double * UnixTimestampToVariantTime(time_t unixTimestamp);

....

dtmGenerated = UnixTimestampToVariantTime(time(NULL)); // This
converts the current unix timestamp (calculated by time(NULL)).

sqlCmdUpdateEvents->Parameters->Append(sqlCmdUpdateEvents-

(ParameterDirectionEnum)adParamInput, sizeof(DATE),
(DATE)*dtmGenerated));

....

// Converts a unix timestamp into one that ADO can decipher
double * UnixTimestampToVariantTime(time_t unixTimestamp)
{
double *dblDBTS = new double;
SYSTEMTIME dbDate;
ZeroMemory(&dbDate, sizeof(SYSTEMTIME));

// Get the tm Struct for the specified unix timestamp
struct tm *timeUnits = localtime(&unixTimestamp);

// Translate the tm struct into a SYSTEMTIME struct
dbDate.wDay = (WORD)timeUnits->tm_mday;
dbDate.wDayOfWeek = (WORD)timeUnits->tm_wday;
dbDate.wHour = (WORD)timeUnits->tm_hour;
dbDate.wMilliseconds = (WORD)0;
dbDate.wMinute = (WORD)timeUnits->tm_min;
dbDate.wMonth = (WORD)timeUnits->tm_mon+1;
dbDate.wSecond = (WORD)timeUnits->tm_sec;
dbDate.wYear = (WORD)timeUnits->tm_year+1900;

// Calculate and return the Variant time for the populated SYSTEMTIME
struct
SystemTimeToVariantTime((LPSYSTEMTIME)&dbDate, dblDBTS);
return dblDBTS;
}

... Just snippets, but you get the idea.

这里SystemTimeToVariantTime是关键,哈哈,我搜索了下果真有个VariantTimeToSystemTime函数,这下就搞定啦
2015-5-25 21:54
0
雪    币: 7068
活跃值: (3517)
能力值: ( LV12,RANK:340 )
在线值:
发帖
回帖
粉丝
12
感谢~
2015-5-25 23:56
0
游客
登录 | 注册 方可回帖
返回
//