我有以下幾點:如何使用WHERE在SQL ID參數
somequery.SQL.Add('UPDATE `someDBname`.`someTABLEname` SET
`client`='''+someForm.Edit1.Text+''',
`phone`='''+someForm.Edit2.Text+''',
`email`='''+someForm.Edit3.Text+''',
`details`='''+someForm.Edit4.Text+''',
`specials`='''+someForm.Edit5.Text+''',
`price`='''+someForm.Edit6.Text+''',
`address`='''+someForm.Edit7.Text+''',
`deadline`='''+someForm.DateTimePicker1.DateTime+''',
`status`='''+someForm.Edit9.Text+'''
WHERE `id`=''' + inttostr(someDataSetid.Value) + ''';');
而且我想切換到使用parameters
,像這樣:
someQuery.SQL.Clear;
someQuery.SQL.Add('UPDATE `someDBname`.`someTABLEname` (client, phone, email, details, specials, price, address, deadline, status) values (:client, :phone, :email, :details, :specials, :price, :address, :deadline, :status) ') ;
someQuery.Params.ParamByName('client').AsString := someForm.Edit1.Text ;
someQuery.Params.ParamByName('telefon').AsString := someForm.Edit2.Text ;
someQuery.Params.ParamByName('email').AsString := someForm.Edit3.Text ;
someQuery.Params.ParamByName('detalii').AsString := someForm.Edit4.Text ;
someQuery.Params.ParamByName('mentiuni').AsString := someForm.Edit5.Text ;
someQuery.Params.ParamByName('pret').AsString := someForm.Edit6.Text ;
someQuery.Params.ParamByName('livrare').AsString := someForm.Edit7.Text ;
someQuery.Params.ParamByName('deadline').AsDateTime := someForm.DateTimePicker1.DateTime ;
someQuery.Params.ParamByName('status').AsString := someForm.Edit9.Text ;
someQuery.ExecSQL(true);
我不知道如何將包含ID
(第一個代碼示例)的WHERE
子句轉換爲parameters
(第二個代碼示例) 還沒弄清楚,我似乎無法在google上找到關於如何在0123中使用WHERE
的示例。 我很使用參數。
我應該在Params.ParamsByName('id')
後寫什麼 - 獲取ID?
服務器是MYSQL
。 請在評論中告訴我如果我遺漏了任何東西,我會編輯
在此先感謝!
爲什麼你認爲你可以改變從使用有效的SQL到無效的SQL爲了添加參數?你的第二個例子根本無效,有或沒有參數。 –
@KenWhite可能是因爲我沒有抓住你顯然做過的事情,而且我還沒有添加到哪裏,我還沒有測試過任何東西。什麼不適用於它? – Petzy
UPDATE的整個語法在你的第二個例子中是錯誤的。首先查看SQL語句,然後在第二行中比較它(不帶參數)。 (實際上,只是將它複製出代碼,將其粘貼到記事本中,然後刪除'SQL.Add('和關閉'');'並讀取它,這完全不同,並且完全無效。語句,它不會改變SQL的整個語法,但你仍然必須編寫語法上有效的SQL語句;你不會只是編寫一種新的語言。 –