TMemo里的內容如下,字串中間是空間隔開。
自己下的代碼如下,但只能添加第一行的記錄。
for I := 0 to memo1.Lines.Count - 1 do
begin
str := memo1.Lines.Strings[I];
str2 := GetValidStr(str, str1, [' ', #9]);
with ADOQuery do
begin
Close;
SQL.Clear;
SQL.Add('select Key from KeyInfo where Key='+''''+Trim(str1)+'''');
Open;
end;
if ADOQuery.RecordCount = 0 then
with ADOQuery do
begin
Close;
SQL.Clear;
SQL.Add('insert into KeyInfo([Key],[PassWord],[Type]) values('''+Trim(str1)+''','''+Trim(str2)+''','''+IntToStr(SpinEdit1.Value)+''')');
ExecSQL;
redSQL;
end
else
Application.MessageBox('添加失敗!!!', '提示資訊', MB_OK + MB_ICONINFORMATION);
Exit;
end;
uj5u.com熱心網友回復:
for I := 0 to memo1.Lines.Count - 1 do
begin
str := memo1.Lines.Strings[I];
str2 := GetValidStr(str, str1, [' ', #9]); //沒法看到函式如何處理
showmessage(str1);//觀察是否每次都一樣?
with ADOQuery do
begin
Close;
SQL.Clear;
SQL.Add('select Key from KeyInfo where Key='+''''+Trim(str1)+'''');
Open;
end;
if ADOQuery.RecordCount = 0 then//當str1不變時,就只有第一次能滿足條件了
with ADOQuery do
begin
Close;
SQL.Clear;
SQL.Add('insert into KeyInfo([Key],[PassWord],[Type]) values('''+Trim(str1)+''','''+Trim(str2)+''','''+IntToStr(SpinEdit1.Value)+''')');
ExecSQL;
redSQL;
end
else
Application.MessageBox('添加失敗!!!', '提示資訊', MB_OK + MB_ICONINFORMATION);
Exit;
end;
uj5u.com熱心網友回復:
if ADOQuery.RecordCount = 0 then...
看下這個運算式的回傳值,后面加一個陳述句 showmessage('Record Count = 0');看是否會顯示這個資訊。
uj5u.com熱心網友回復:

我想問下留上各位 ,你們的代碼是寫在那個軟體里的
uj5u.com熱心網友回復:
?樓上什么意思?uj5u.com熱心網友回復:
str := memo1.Lines.Strings[I];str2 := GetValidStr(str, str1, [' ', #9]);
關鍵是這兩句,str,str1,str2的值肯定有問題!
uj5u.com熱心網友回復:
GetValidStr是自己寫的函式,取空格后面的字串的。uj5u.com熱心網友回復:
只添加一筆,表明if ADOQuery.RecordCount = 0 then不成立了即GetValidStr函式回傳的str1值都一樣,檢查一下GetValidStr函式吧
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/157028.html
標籤:數據庫相關
