下面的VB代码在DELPHI里怎么写?(请熟悉VB和DELPHI的朋友帮帮我)
dim cnn As New ADODB.Connection
dim rs As New ADODB.Recordset
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\ACCESS数据库;Persist Security Info=True"
cnn.Open ConnStr
rs.open "select * from 数据表或查询"
do until rs.eof
控件1.TEXT=rs("字段1").value
. .
. .
. .
控件n.TEXT=rs("字段n").value
rs.movenext
loop
rs.close
set rs=nothing
cnn.close
set cnn=nothing
Delphi里面一般是用数据控件:TAdoQuery,TQuery,小弟也是刚学不久,还不懂能不能象VB一样:
dim rs as New AdoDB.RecordSet
这样吧,再给你一段处理SQL语句的函数:
Function HandSQL(AAdoQuery: TAdoQuery;ASQL: string):Boolean;
begin
Result:=True;
try
with AAdoQuery do begin
Close;
SQL.Clear;
SQL.Add(ASQL);
if Pos('SELECT',UpperCase(ASQL)) > 0 then
Open
else
ExecSQL;
end;
except
on E: Exception do begin
Result:=False;
Application.MessageBox(PChar(BS_HNDSQL+E.Message),BS_PROMPT,MB_ICONINFORMATION);
end;
end;
end;