lazarus连接access数据库
连接:
用控件ODBCConnection
var sql: string; begin ODBCConn.Driver:= 'Microsoft Access Driver (*.mdb)'; ODBCConn.Params.Add('DBQ=D:\0fastdata\' + utf8ToSys('access数据库.mdb')); ODBCConn.Params.Add('codepage = UTF8'); ODBCConn.Open; if ODBCConn.Connected then memo1.Lines.Add('odbc Conn Access is ok') else memo1.Lines.Add('odbc Conn Access is error'); sql:='select * from 单位表'; SQLQueryAdo.Close; SQLQueryAdo.SQL.Clear; SQLQueryAdo.SQL.Add(utf8ToSys(sql)); SQLQueryAdo.Open;
插入数据:
用TSQLQuery控件
var sql: string; begin // sql := 'insert into 单位表 (col1) values(''aabbcc'')'; sql := utf8ToSys(sql); try SQLQueryCmd.SQL.Text := sql; SQLQueryCmd.ExecSQL; except on E: Exception do begin log('ACCESS SQL语句执行出错: '+ sql); memo1.Lines.Add('ACCESS SQL语句执行出错: '+ sql); log(E.Message); end; end;