console程式內使用了ADO與NMSMTP元件,編譯及連結都沒錯誤,但執行時會出現錯誤訊息
我的程式碼如下
//------------------------------------------------------------------
#include
#include
#include
#include #pragma hdrstop //------------------------------------------------------------------
TNMSMTP *nmsmtp1 = new TNMSMTP(NULL);
TADOConnection *ADOConn_Emp = new TADOConnection(NULL);
TADOConnection *ADOConn_iServer = new TADOConnection(NULL);
TADOConnection *ADOConn_a = new TADOConnection(NULL);
TADOQuery *ADOQ_Rest = new TADOQuery(NULL);
TADOQuery *ADOQ_iServer = new TADOQuery(NULL);
TADOQuery *ADOQ_Atten = new TADOQuery(NULL);
//------------------------------------------------------------------
void set_mail()
{
nmsmtp1->Host = "192.168.1.200";
nmsmtp1->UserID = "John";
nmsmtp1->Charset = CHINESEBIG5_CHARSET;
nmsmtp1->Connect();
nmsmtp1->SubType = mtHtml;
} void set_database()
{ //設定有關資料庫方面的設定
ADOConn_Emp->Name = "ADOConn_Emp";
ADOConn_Emp->LoginPrompt = false;
ADOConn_Emp->ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=Employee;Extended Properties=\"DSN=Employee;UID=;SourceDB=C:\DATABASE\EMPLOYEE\EMPLOYEE.DBC;SourceType=DBC;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;Null=Yes;Deleted=Yes;\"";
ADOConn_Emp->DefaultDatabase = "C:\\DATABASE\\EMPLOYEE\\EMPLOYEE.DBC"; ADOConn_iServer->Name = "ADOConn_iServer";
ADOConn_iServer->LoginPrompt = false;
ADOConn_iServer->ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\john\\My Documents\\acclog.mdb;Persist Security Info=False";
ADOConn_iServer->DefaultDatabase = "C:\\Documents and Settings\\john\\My Documents\\acclog"; ADOConn_a->Name = "ADOConn_a";
ADOConn_a->LoginPrompt = false;
ADOConn_a->ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=service;Extended Properties=\"DSN=service;DESC=MySQL ODBC 3.51 Driver DSN;DATABASE=eta;SERVER=service.eta.com.tw;UID=service;PASSWORD=eta2003;PORT=3306;OPTION=3;STMT=;\";Initial Catalog=service";
ADOQ_Rest->Connection = ADOConn_Emp;
ADOQ_Rest->Active = false;
ADOQ_Rest->SQL->Add("select * from 請假單 where 員工編號 = :num and 起始日期 >= :date1 and 起始日期 <= :date2");
ADOQ_iServer->Connection = ADOConn_iServer;
ADOQ_iServer->Active = false;
ADOQ_iServer->SQL->Add("select EmployeeID, LastName, Department, TakeDate, LeaveDate, Manager, Rotation, EmpStatus, TakeTime, LeaveTime from Employee order by EmpStatus desc, Department, EmployeeID");
ADOQ_iServer->ExecSQL();
ADOQ_iServer->Active = true;
ADOQ_Atten->Connection = ADOConn_a;
ADOQ_Atten->Active = false;
ADOQ_Atten->SQL->Add("select * from attendance where ad_Sn = :emp_id and ad_Date = :date"); }
//------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
int t2;
TDate date3; //設定有關電子郵件方面的設定
set_mail();
//設定有關資料庫方面的設定
set_database(); //依照Employee內有的員工去做檢查
for ( int i1 = 0 ; i1 < ADOQ_iServer->RecordCount ; i1++ )
{
//取出員工編號在這段期間的請假紀錄
ADOQ_Rest->Active = false;
ADOQ_Rest->Parameters->Items[0]->Value = "000110";
ADOQ_Rest->Parameters->Items[1]->Value = StrToDate("2005/11/1");
ADOQ_Rest->Parameters->Items[2]->Value = StrToDate("2005/11/30");
ADOQ_Rest->ExecSQL();
ADOQ_Rest->Active = true;
//test1.set_rest(ADOQ_Rest); //從設定的天數開始,一天一天作檢查
for ( date3=StrToDate("2005/11/1") ; date3 <= StrToDate("2005/11/30") ; date3++ )
{
//取出當天(date3)的進出紀錄,取出第一筆與最後一筆的時間
ADOQ_Atten->Active = false;
ADOQ_Atten->Parameters->Items[0]->Value = "0110";
ADOQ_Atten->Parameters->Items[1]->Value = date3.FormatString("yyyymmdd");
ADOQ_Atten->ExecSQL();
ADOQ_Atten->Active = true;
cout << ADOQ_Atten->Fields->Fields[2]->AsString.c_str() << endl;
ADOQ_Atten->Next();
}
}
cin >> t2;
return 0;
}
//-------------------------------------------------------------------