我通过ADO往Oracle的一张表里插数据,建表语句如下:
--创建motor_run_info表
create table motor_run_info
(
motor_run_info_id number(6) not null primary key,
motor_id number(6) not null,
motor_name varchar2(30) not null,
coach_id char(10) not null,
motor_project char(30) not null,
motor_project_value number(8,2) not null,
state_time date not null
);--创建motor_run_seq sequence
create sequence motor_run_seq
increment by 1
start with 1
nocycle
nomaxvalue
cache 10;--创建触发器
create trigger motor_run_info_trig before
insert on motor_run_info for each row
begin
select motor_run_seq.nextval into:New.motor_run_info_id from dual;
end;然后添加语句如下: 1 CString flagStr;
2 // COleVariant VariantTime;
3 // VariantTime=Sdata[18];
4 // VariantTime.ChangeType(VT_DATE);
5 COleDateTime DataTime=COleDateTime::GetCurrentTime();
6 // CComVariant tempDate=DataTime;
7 for(i=5;i<=10;i++)
8 {
9 fprintf(fpw2,"%s ",Sdata[i]);
10 switch(i)
11 {
12 case 5:
13 flagStr="A相电流";
14 break;
15 case 6:
16 flagStr="B相电流";
17 break;
18 case 7:
19 flagStr="C相电流";
20 break;
21 case 8:
22 flagStr="转速值";
23 break;
24 case 9:
25 flagStr="转矩值";
26 break;
27 case 10:
28 flagStr="温度";
29 break;
30 }
31 m_pRecordset->AddNew();
32 m_pRecordset->PutCollect("motor_id",(_bstr_t)Sdata[0]);
33 m_pRecordset->PutCollect("motor_name",(_bstr_t)Sdata[1]);
34 m_pRecordset->PutCollect("coach_id",(_bstr_t)Sdata[4]);
35 m_pRecordset->PutCollect("motor_project",(_bstr_t)flagStr);
36 m_pRecordset->PutCollect("motor_project_value",(_bstr_t)Sdata[i]);
37 m_pRecordset->PutCollect("state_time",(_variant_t)DataTime);
38 m_pRecordset->Update();
39 }注明一下:SData[i]是CString类型的。出错情况:每次运行到上面代码的38行就出现异常:Unhandled Exception in XXX.exe 0xE06D7363 Microsoft C++Exception.谁能帮我看看是怎么回事?已经两天了,~~~~(>_<)~~~~ 。
--创建motor_run_info表
create table motor_run_info
(
motor_run_info_id number(6) not null primary key,
motor_id number(6) not null,
motor_name varchar2(30) not null,
coach_id char(10) not null,
motor_project char(30) not null,
motor_project_value number(8,2) not null,
state_time date not null
);--创建motor_run_seq sequence
create sequence motor_run_seq
increment by 1
start with 1
nocycle
nomaxvalue
cache 10;--创建触发器
create trigger motor_run_info_trig before
insert on motor_run_info for each row
begin
select motor_run_seq.nextval into:New.motor_run_info_id from dual;
end;然后添加语句如下: 1 CString flagStr;
2 // COleVariant VariantTime;
3 // VariantTime=Sdata[18];
4 // VariantTime.ChangeType(VT_DATE);
5 COleDateTime DataTime=COleDateTime::GetCurrentTime();
6 // CComVariant tempDate=DataTime;
7 for(i=5;i<=10;i++)
8 {
9 fprintf(fpw2,"%s ",Sdata[i]);
10 switch(i)
11 {
12 case 5:
13 flagStr="A相电流";
14 break;
15 case 6:
16 flagStr="B相电流";
17 break;
18 case 7:
19 flagStr="C相电流";
20 break;
21 case 8:
22 flagStr="转速值";
23 break;
24 case 9:
25 flagStr="转矩值";
26 break;
27 case 10:
28 flagStr="温度";
29 break;
30 }
31 m_pRecordset->AddNew();
32 m_pRecordset->PutCollect("motor_id",(_bstr_t)Sdata[0]);
33 m_pRecordset->PutCollect("motor_name",(_bstr_t)Sdata[1]);
34 m_pRecordset->PutCollect("coach_id",(_bstr_t)Sdata[4]);
35 m_pRecordset->PutCollect("motor_project",(_bstr_t)flagStr);
36 m_pRecordset->PutCollect("motor_project_value",(_bstr_t)Sdata[i]);
37 m_pRecordset->PutCollect("state_time",(_variant_t)DataTime);
38 m_pRecordset->Update();
39 }注明一下:SData[i]是CString类型的。出错情况:每次运行到上面代码的38行就出现异常:Unhandled Exception in XXX.exe 0xE06D7363 Microsoft C++Exception.谁能帮我看看是怎么回事?已经两天了,~~~~(>_<)~~~~ 。
try
{
......
}
catch(_com_error &e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description()); // Print Com errors.
TRACE(_T("Error\n"));
TRACE(_T("\tCode = %08lx\n"), e.Error());
TRACE(_T("\tErrorMessage = %s\n"), (LPCTSTR)e.ErrorMessage());
TRACE(_T("\tSource = %s\n"), (LPCTSTR) bstrSource);
TRACE(_T("\tDescription = %s\n"), (LPCTSTR) bstrDescription);
}