procedure TForm1.btn1Click(Sender: TObject);
var
Connection: TSQLConnection;
query: TSQLQuery;
ds1:TSQLDataSet;
begin
try
Connection := TSQLConnection.Create(nil);
Connection.LoginPrompt:=false;
Connection.DriverName := 'dbxmysql';
Connection.GetDriverFunc := 'getSQLDriverMYSQL50';
Connection.LibraryName := 'dbxopenmysql50.dll';
Connection.VendorLib := 'libmysql.dll';
Connection.Params.Append('Database=ecshop');
Connection.Params.Append('User_Name=root');
Connection.Params.Append('ServerCharset=GB2312');
Connection.Params.Append('Password=mypassowrd');
Connection.Params.Append('HostName=127.0.0.1');
Connection.Open;
except
MessageBox(Handle, '数据库连接错误,请检查数据库用户名或密码.', '提示',
MB_OK + MB_ICONINFORMATION);
Exit;
end;
try
query:= TSQLQuery.Create(nil);
query.SQLConnection:= Connection;
query.SQL.Clear;
query.SQL.Add('select * from ecs_goods limit 10');
query.Open;
if query.RecordCount<>0 then
begin
caption:= query.Fields[3].Value;
end;
except
end;
end;