如何在 Muilty Thread 中建立TQuery並正確執行 |
尚未結案
|
jimmy_and_you
初階會員 發表:20 回覆:74 積分:33 註冊:2003-05-12 發送簡訊給我 |
小弟我欲開發一個Server端的DB Agent,所以用Muilty Thread 建立連線並讀寫資料庫,Muilty Thread 端的程式碼為: int TestNum = 0;
void __fastcall ServiceThread::Execute()
{
int ans; TestNum++;
ServiceQuery = new TQuery( Form1->GetParentComponent() );
ServiceQuery->Close();
ServiceQuery->SQL->Clear();
ServiceQuery->DatabaseName = "WD";
ServiceQuery->SQL->Add("INSERT jimmytest ( StationID , Status ,
LastFlow , SerialNumber )");
ServiceQuery->SQL->Add("VALUES ( " + ((AnsiString)(TestNum))
+ ", '" + (AnsiString) (TestNum))
+ "' , '" + ((AnsiString)(TestNum))
+ "' ," + ((AnsiString)(TestNum)) +" )"); ServiceQuery->Active = true; //<--這2行會出現ERROR Message
ServiceQuery->Open(); //<--這2行會出現ERROR Message while(1)
{
if ( (ans=recv(ConnectSocket, szMessage, 256, 0)) ==
SOCKET_ERROR )
{
Connects --;
Form1->Show->Text = (AnsiString) Connects;
FreeOnTerminate = true;
Terminate();
break;
}
else
{
Form1->Rec_Message->Text = (AnsiString) szMessage;
}
}
} Error Message 內容為:
Project server.exe raised execepion class ENoResultSet with message 'Error creating cursor handle'. Process stopped. Use Step or Run to continue. 我使用的Data Base 是MySQL 3.511版
Data Base方面我是新手,請大家多多指教
|
tech_state
版主 發表:44 回覆:638 積分:641 註冊:2003-02-10 發送簡訊給我 |
jimmy_and_you, 您好
請修改一下您的code
ServiceQuery = new TQuery(Owner); ServiceQuery->Active = true; //<--這2行會出現ERROR Message ServiceQuery->Open(); //<--這2行會出現ERROR Message以上二行code,請刪除第一行,第二行改為ServiceQuery->ExecSQL(); ======================= 涵養怒中氣。謹防順口言。留心忙裡錯。珍惜有時錢。 是非終日有,不聽自然無 天下本無事,庸人自擾之 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |