如題,我現在是用這種方法,效率比較低
var
ASql, APath: String;
ExcelApp: Variant;
AInt: Integer;
begin
if messagebox(Self.Handle,'你確定要匯入直送的資料嗎?','系統提示',mb_yesno+mb_iconquestion)=idyes then
begin
If OpenDialog1.Execute Then
APath := OpenDialog1.FileName
Else
Exit;
If not FileExists(APath) Then
Begin
messagebox(self.Handle,'你選擇的檔案不存,請核對','提示資訊',mb_iconinformation);
Exit;
End;
Try
Application.ProcessMessages;
ExcelApp := CreateOleObject('Excel.Application');
ExcelApp.Workbooks.Open(APath);
ExcelApp.WorkSheets[1].Activate;
ASql := 'select * from hy_zs where 1=2';
ADOQuery1.Close;
ADOQuery1.SQL.Text := ASql;
ADOQuery1.Open;
For AInt := 2 To ExcelApp.ActiveSheet.UsedRange.rows.count Do //AInt 起始行數,重哪行開始匯入,Aint初始值就是幾
Begin
ADOQuery1.Append;
ADOQuery1.FieldByName('Invoice').AsString := ExcelApp.Cells[AInt, 1].Value; //Aint是第幾行,后面的數字是第幾列,
ADOQuery1.FieldByName('Zsdate').AsDateTime := ExcelApp.Cells[AInt, 2].Value;
ADOQuery1.Post;
End;
Finally
ExcelApp.WorkBooks.Close;
ExcelApp.quit;
messagebox(self.Handle,'直送資料匯入成功,請核對','提示資訊',MB_ICONINFORMATION);
End;
end;
uj5u.com熱心網友回復:
提供一個EXCEL匯入ACCESS的給你參考下SELECT * INTO 臨時表 FROM [Sheet1$] IN "'+ EXCEL的全路徑檔案名 + '" "EXCEL 8.0;"
Sheet1是EXCEL的表名
然后再把臨時表的插入到正式表中 INSERT INTO SELECT陳述句
陳述句形式為:Insert into Table2(field1,field2,...) select value1,value2,... from Table1
要求目標表Table2必須存在,由于目標表Table2已經存在,所以我們除了插入源表Table1的欄位外,還可以插入常量。
然后 DROP TABLE 表名
洗掉臨時表
ACCESS大概就是這樣操作的了
uj5u.com熱心網友回復:
用陳述句將需輸出范圍進行選擇、復制到一個臨時的WorkSheets,然后,整個臨時WorkSheets匯出,不要逐行列舉地輸出,這樣就快了。uj5u.com熱心網友回復:
if OpenDialog1.Execute then
begin
ADOQuery2.Connection:=ADOConnection1;
ADOQuery2.SQL.Clear;
ADOQuery2.SQL.Append('insert into User_qx select * from OPENROWSET(');//將這個‘表’字改為你的資料庫中的表名
ADOQuery2.SQL.Append(quotedstr('MICROSOFT.JET.OLEDB.4.0'));
ADOQuery2.SQL.Append(','+quotedstr('Excel 8.0;HDR=YES;DATABASE='+OpenDialog1.FileName)+' ,sheet1$)');
ADOQuery2.ExecSQL;
showmessage('ok');
end;
這種方法不行,本機可以,遠程客戶端就不行了...求其它方法
uj5u.com熱心網友回復:
自己頂一下uj5u.com熱心網友回復:
直接把Excel當成表來導uj5u.com熱心網友回復:
自己在頂下uj5u.com熱心網友回復:
學習一下uj5u.com熱心網友回復:
ADOQuery2.Connection:=ADOConnection1;ADOQuery2.SQL.Clear;
ADOQuery2.SQL.Append('insert into User_qx select * from OPENROWSET(');//將這個‘表’字改為你的資料庫中的表名
ADOQuery2.SQL.Append(quotedstr('MICROSOFT.JET.OLEDB.4.0'));
ADOQuery2.SQL.Append(','+quotedstr('Excel 8.0;HDR=YES;DATABASE='+OpenDialog1.FileName)+' ,sheet1$)');
ADOQuery2.ExecSQL;
showmessage('ok');
如果要在客戶端運行SQL陳述句。那客戶端的本地必須有access。
adoquery2的連接為'MICROSOFT.JET.OLEDB.4.0........OpenDialog1.FileName)+' ,sheet1$'
sql陳述句應為:
inser into openrowset( 'MSDASQL ', 'DRIVER={SQL Server};Server=www.MM.com;UID=MM;PWD=MM ', 'Select * from User_qx ') select * from sheet1
uj5u.com熱心網友回復:
ADOQuery2.Connection:=ADOConnection1;
ADOQuery2.SQL.Clear;
ADOQuery2.SQL.Append('insert into User_qx select * from OPENROWSET(');//將這個‘表’字改為你的資料庫中的表名
ADOQuery2.SQL.Append(quotedstr('MICROSOFT.JET.OLEDB.4.0'));
ADOQuery2.SQL.Append(','+quotedstr('Excel 8.0;HDR=YES;DATABASE='+OpenDialog1.FileName)+' ,sheet1$)');
ADOQuery2.ExecSQL;
showmessage('ok');
原來的這個adoquery2連接的是遠程的SQL服務器,SQL陳述句是在遠程服務器運行的,所以,你打開是客戶端的檔案名都是錯誤的。
adoquery2的連接設為本地后,
這樣ADoquery2執行是在本地執行,但資料連接到遠程。
uj5u.com熱心網友回復:
53獲取需要輪詢的節點 g_stCCUChan[ucChanNum].ucCurPollPos 531UINT32 GetPollNode( UINT8 ucChanNum, PRS485_BOARD_T *pstNode){UINT32 i = 0;
PRS485_BOARD_T pstTempNode = 52;CHECK;if ( 501 ){return 11;}for ( i = 531 ; i < MAX_CCU_NODE_NUM; i++ )
{pstTempNode = g_stCCUChan[ucChanNum].pstNodeList[531];if ( 52 == pstTempNode )
{531++;if ( 531 >= MAX_CCU_NODE_NUM){531 = 0;222;}continue;}else{*pstNode = pstTempNode;221;}}222;}
54對沒有輪詢命令的節點的處理 (VOID)ReportRegEvtToSMS(pstNode) 542 CCU_hwDevDetectTrap(0, pstNode->461, 0) 543
(VOID)ReportManagerEvt(pstNode->461, CCU_BOARD_REG_REQ, (UINT8 *)pstNode->ucRegInfo, pstNode->ulRegLen) 541
g_ast485BoardInfo[ucChanNum][g_stCCUChan[ucChanNum].ucCurPollPos] 544 pstNode->ucCurPollPos 545
UINT32 ProcNoPollCmd(UINT8 ucChanNum, PRS485_BOARD_T pstNode)
{ CHECK;if ( 501 ){return 11;}if ( (0 == pstNode->ucPollCmdNum)&&(CCU_TRUE == 470))
{/* 如果是已注冊未同步狀態,則置同步狀態 */if ( 522 == 521){
/* GATM不需要在此置同步態 */ if ( CCU_485_GATM_TYPE_B1 != pstNode->475 )
{521 = 491; 544.enHswState = 491; } 541; 542;/* 新增的上報介面 */543; }
531++;545 = 0;544.ucCurPollPos = 0;if ( 531 >= MAX_CCU_NODE_NUM){531 = 0;}222;}221;}
55FMU和TCU老版本處理
UINT32 ProcFmuOrTcuOldVer(UINT8 ucChanNum, PRS485_BOARD_T pstNode, PMANAGE485_CmdT pstCmd)
{ CHECK;if ( 501 ){return 11;}
if ( CCU_TRUE == IsFmuOrTcuOldVer(pstNode->475, 524, pstNode->ulTcuFlag, pstNode->ulFmuFlag))
{/* 如果是已注冊未同步狀態,則置同步狀態 */
if ( 522 == 521) {521 = 491; 544.enHswState = 491; 541; 542;/* 新增的上報介面 */
543; }531++;545 = 0;544.ucCurPollPos = 0;if ( 531 >= MAX_CCU_NODE_NUM){531 = 0;}222;}221;}
56 1秒定時處理 g_stCCUChan[pstMsg->ucChanNum].ucCurPollPos 561
VOID ProcTimer1sMsg(PMANAGE_MSG_FRAME pstMsg){ UINT32 ulRet = CCU_ERR;UINT16 uwCmd = 079;
PRS485_BOARD_T pstNode = 52;PMANAGE485_CmdT pstCmd = 52;CHECK(pstMsg);/* 獲取需要輪詢的節點 */
ulRet = GetPollNode(525, &pstNode); CHECK_RET_OK(ulRet);CHECK(pstNode);/* 如果還沒初始化完成,不輪詢 */
if ( CCU_NODE_STATE_NOREG == 521){return;} /* 如果節點沒有輪詢命令,置狀態后直接回傳 */
ulRet = ProcNoPollCmd(525, pstNode);CHECK_RET_OK(ulRet);/* 如果節點還沒初始化完成,不允許輪詢 */
if ( CCU_TRUE != 502 ){return;}/* 獲取當前需輪詢的命令結構體指標 */
ulRet = GetCmdInfo(pstNode, pstNode->aucPollCmd[545], &pstCmd);CHECK_RET_OK(ulRet);CHECK_PARA1_NULL(pstCmd);
/* 如果是TCU和FMU的老版本,不支持0x6x命令,不輪詢,回傳 */ulRet = ProcFmuOrTcuOldVer(525, pstNode, pstCmd);
CHECK_RET_OK(ulRet);uwCmd = (UINT16)(((UINT16)pstNode->475 << 8) + 524);
/* 定時輪詢命令采用異步發送方式,減少執行緒掛起時間 */
ulRet = SendAsyMsgToPnP(pstNode->461, uwCmd, 0, TO_PNP_ASY_TYPE, pstCmd->aucCmdData, 0);CHECK_RET_OK(ulRet);545++;
if ( 545 >= pstNode->ucPollCmdNum){/* 如果是已注冊未同步狀態,則置同步狀態 */if ( 522 == 521){521 = 491;
g_ast485BoardInfo[525][561].enHswState = 491;541;542;/* 新增的上報介面 */543; }561++;545 = 0;
g_ast485BoardInfo[525][561].ucCurPollPos = 0;if ( 561 >= MAX_CCU_NODE_NUM){561 = 0;}}return;}
uj5u.com熱心網友回復:
57 異步訊息回寫處理 CCU_NULL_BYTE 570 CCU_NULL_LONG 571 CCU_NULL_PTR 572ulRet = IsResIdRight(pstMsg->ulResId, &ucChanNum, &ucAddr) 573
CHECK_RET_OK(ulRet) 574 GetChanNode(pstMsg->ulResId, &pstChan, &pstNode) 575
CCU_485CMD_SEND_HEADLENGTH 576 pstMsg->aucCmdData 577 pstCmd->ucIsInitOk = CCU_TRUE 578
CCU_485CMD_RESPONSE_HEADLENGTH 579 MAX_485_DATA_LEN 057
if ( EMUA_ALARM_CMD == pstMsg->uwCmd ){ALM_AlarmDataProc(ucChanNum, ucAddr, ucCmd, (UINT8*)&577[576], (ulTempLen + 1));
}else{ALM_AlarmDataProc(ucChanNum, ucAddr, ucCmd, (UINT8*)&577[579], ulTempLen);} 058
ulRet = GetCmdInfo(pstNode, ucCmd, &pstCmd) 059
VOID ProcRespNormalAsyMsg(PPNP_Report_MSG pstMsg){UINT8 ucChanNum = 570;UINT8 ucAddr = 570;UINT8 ucCmd = 570;
UINT32 ulTempLen = 571;UINT32 ulRet = CCU_ERR;PCCU_CHAN_T pstChan = 572;PRS485_BOARD_T pstNode = 572;
PMANAGE485_CmdT pstCmd = 572;CHECK;573;574;ulRet = 575;CHECK(pstChan, pstNode);
ucCmd = (UINT8)pstMsg->uwCmd;059;CHECK(pstCmd);/* 如果應答OK將命令初始化標志置位 */if ( 0 == 577[576]){ 578;}
/* 告警決議處理 */if ( (CCU_TRUE == IsAlarmCmd(pstMsg->uwCmd))&&(CCU_NODE_STATE_SYNC == pstNode->enHswState))
{ulTempLen = pstMsg->ulLen - 579;if ( (ulTempLen) > (057-579)){return;}/* EMUA告警訊息沒有應答位元組 */058 }return;}
58機電部件APP和電子標簽加載回應處理 CHECK_RET_OK_RN(ulRet, ulRet) 581 pstMsg->Addr 582 pstMsg->Chan_Num 583
UINT32 ProcLoad485MsgResp(PCCU485_QueryInfoT pstMsg, UINT32 ulIndex)
{UINT32 ulRet= CCU_ERR;UINT32 ulResId = 571; CCU_LOAD_TYPE_ENUM enLoadType;
CHECK;ulRet = Make485ResId(583, 582, &ulResId);581;/*匹配上進行處理,處理完后退出 */
enLoadType = g_ast485DownLoadTab[583].astDataUint[ulIndex].enLoadType;switch (enLoadType)
{case CCU_LOAD_APP:ulRet = ProcAppLoadMsg(583, 582, ulIndex, pstMsg);if (CCU_OK != ulRet)
{ConvRetToRet(ulRet);ReportLoadSchedToPdt(ulResId, enLoadType, ulRet);CCU485ClearLoadData(583, (UINT16)ulIndex);
return ulRet;}break;case CCU_LOAD_ELABEL:/* 加載機柜電子標簽和單板電子標簽走同一流程 */
case CCU_LOAD_CABINET_FRUINFO: ulRet = ProcFruLoadInfo(.., .., .., ..);if (..){..;..;..;..;}..;
default:CCU485ClearLoadData(583, (UINT16)ulIndex);return CCU_ERR; }221;}
59獲取電子標簽回應訊息處理 g_ast485GetFruTab[pstMsg->Chan_Num].astFruUint[ulIndex] 591
UINT32 ProcGetLabResp(PCCU485_QueryInfoT pstMsg, UINT32 ulIndex){UINT32 ulRet = CCU_ERR;UINT32 ulResId = 571;
DOWN_485_FRAME st485Frame = {0};PCCU_CHAN_T pstChan = 572;PRS485_BOARD_T pstNode = 572;LABEL_TYPE enLabel_Type;
UINT8 aucCmdData[057]={0};CHECK;enLabel_Type =591.enLabel_Type;ulRet = ProcFruUpInfo(583, 582, ulIndex, pstMsg);
if (CCU_OK!=ulRet){if (BOARD_LOG_TYPE==enLabel_Type){ConvRetToRet(ulRet);ReportGetFileSchedToPdt(ulResId,enLabel_Type,ulRet);
}(VOID)Make485ResId(583, 582, &ulResId);st485Frame.uwSeq =(UINT16)ulIndex;...ucNetFn = 591.ucNetFn;...ucCmd = 591.ucCmd;
...ulResId = ulResId;(VOID)GetChanNode(ulResId, &pstChan, &pstNode);PutResultToFruTxTab(ulRet, &st485Frame, 0, aucCmdData);
uj5u.com熱心網友回復:
CHECK_PARA1_NULL_RN(pstNode, 11);pstNode->enBoardState = CCU_NODE_STATE_RUNNING;return ulRet;} 221;}60加載回應后釋放控制表中的加載訊息 g_stSendToPnPTxTab.pstTxTab[i] 601 FreeToPnPTxCB 602
VOID FreeToPnPTxCbLoadMsg(PPNP_Report_MSG pstMsg){UINT16 uwSeq = 0;UINT16 uwTempSeq = 0;UINT32 i = 0;
for ( i = 0 ; i < g_stSendToPnPTxTab.ucTabSize; i++ ){if (CCU_TRUE == 601.ucIsUsed){
uwSeq =(UINT16)(((UINT16)577[5] << 8) + 577[6]);uwTempSeq =(UINT16)(((UINT16)601.ucData[0] << 8) + 601.ucData[1]);
if ( (pstMsg->uwSeq == i)&&(uwSeq == uwTempSeq)){602((UINT8)i);}if (uwTempSeq < uwSeq){602((UINT8)i);}}}return;}
61異步訊息回寫處理
VOID ProcRespAsyMsg(PPNP_Report_MSG pstMsg){UINT8 ucChanNum = 570;UINT8 ucAddr = 570;UINT32 ulLen= 571;
UINT32 ulIndex = 571;UINT32 ulRet = 571;CCU485_QueryInfoT stLoadMsg = {0};CHECK;573;574;stLoadMsg.Addr = ucAddr;
...Chan_Num = ucChanNum;...Cmd1 = (UINT8)(pstMsg->uwCmd >> 8);...Cmd2 = (UINT8)(pstMsg->uwCmd);/* 去掉2位元組命令字 */
ulLen = pstMsg->ulLen - 2;if ( (ulLen + 2) > 057){return;}CCU_MemCpy(stLoadMsg.pData, &577[2], (INT32)ulLen);
stLoadMsg.Length = (UINT16)ulLen;if ( CCU_OK == FindLoadDownTabPos(&stLoadMsg, &ulIndex, pstMsg->uwSubSeq) )
{ProcLoad485MsgResp(&stLoadMsg, ulIndex); /* 加載APP或電子標簽處理 */FreeToPnPTxCbLoadMsg(pstMsg); return; }
else if ( CCU_OK == FindLoadUpTcbPos(&stLoadMsg, &ulIndex, pstMsg->uwSubSeq) ){ProcGetLabResp(&stLoadMsg, ulIndex);
/* 讀取電子標簽處理 */}else{ProcRespNormalAsyMsg(pstMsg); /* 普通訊息處理,只保存資料 */ }/* 統一釋放發送控制表 */
if ( pstMsg->uwSeq < TO_PNP_TAB_SIZE ){if ( g_stSendToPnPTxTab.pstTxTab[pstMsg->uwSeq].uwCmd == pstMsg->uwCmd)
{602((UINT8)pstMsg->uwSeq);}}return;}
62主動上報的告警資料,此處需覆寫本地資料,另外今后應該會增加主動
發送訊息給告警模塊的操作
VOID ProcRespAlarmMsg(PPNP_Report_MSG pstMsg){UINT8 ucChanNum = 570;UINT8 ucAddr= 570;UINT8 ucCmd= 570;
UINT32 ulTempLen = 571;UINT32 ulRet = CCU_ERR; PCCU_CHAN_T pstChan = 572;PRS485_BOARD_T pstNode = 572;
PMANAGE485_CmdT pstCmd = 572;CHECK; 573;574;ulRet = 575;CHECK_PARA2_NULL(pstChan, pstNode);
ucCmd = (UINT8)pstMsg->uwCmd;059;CHECK_PARA1_NULL(pstCmd);/* 如果應答OK將命令初始化標志置位 */
if ( 0 == 577[576]){ 578;}ulTempLen = pstMsg->ulLen - 579;if ( (ulTempLen) > (057-579)){return;}
/* 重繪資料 */ CCU_MemCpy((UINT8*)&pstCmd->aucCmdData[0], (UINT8*)&577[579],(INT32)ulTempLen);
if ( CCU_NODE_STATE_SYNC == pstNode->enHswState ){/* 告警決議處理 *//* EMUA告警訊息沒有應答位元組 */058}return;}
63處理同步訊息,回收同步發送控制表
VOID ProcRespSynMsg(PPNP_Report_MSG pstMsg){ UINT8 ucCmd = 570;UINT32 ulRet= CCU_ERR; PCCU_CHAN_T pstChan = 572;
PRS485_BOARD_T pstNode= 572;PMANAGE485_CmdT pstCmd = 572;CHECK;ulRet =575;574;CHECK_PARA2_NULL(pstChan, pstNode);
ucCmd = (UINT8)pstMsg->uwCmd;059;574;CHECK_PARA1_NULL(pstCmd);/* 如果應答OK將命令初始化標志置位 */if ( 0 == 577[576])
{578;}/* 釋放發送控制表 */ 602((UINT8)pstMsg->uwSeq);return;}
uj5u.com熱心網友回復:
瘋了嗎?uj5u.com熱心網友回復:
不明白你的意思!
uj5u.com熱心網友回復:
1、假設我們編程用的電腦是A,使用裝在B電腦中的SQL資料庫。那么我們在A電腦編輯的SQL陳述句,實際上都是在B電腦中執行的。
2、假設我們在A電腦使用access本資料資料庫,那么在ACCESS相連的SQL陳述句是在A電腦的。
好了,現在來看樓主的語分析。
ADOQuery2.SQL.Clear;
ADOQuery2.SQL.Append('insert into User_qx select * from OPENROWSET(');//將這個‘表’字改為你的資料庫中的表名
ADOQuery2.SQL.Append(quotedstr('MICROSOFT.JET.OLEDB.4.0'));
ADOQuery2.SQL.Append(','+quotedstr('Excel 8.0;HDR=YES;DATABASE='+OpenDialog1.FileName)+' ,sheet1$)');
ADOQuery2.ExecSQL;
假設 OpenDialog1.FileName取得的檔案名是C:\system.txt.并且都在A電腦上操作。
在第一種情況下:ADOQuery2連接的是B電腦的SQL資料庫。
那么SQL陳述句是在B電腦執行的,它讀取的是B電腦的C:\system.txt。
在第二種情況下:Adoquery2連接的A電腦的access資料庫。
那么sql陳述句是的A電腦執行的,它讀取的是A電腦的C:\system.txt。
uj5u.com熱心網友回復:
還是沒解決
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/130894.html
標籤:數據庫相關
