zoukankan      html  css  js  c++  java
  • Delphi学习之 FireDAC

    用FireDAC在access数据库中添加一行数据,此处利用的是SQL语句插入方法

    procedure TForm1.btnInsertDataClick(Sender: TObject);
    var
    myCom : TFDCommand;
    myQry : TFDQuery;
    myConn : TFDConnection;
    sql : string;
    begin

    sql := 'Insert Into tpUsers(userName,userPwd) values (''10795'',''xx'')';

    myConn := TFDConnection.Create(nil);
    myConn.Params.DriverID := 'MSACC';
    myConn.Params.Database := 'D:TestDelphiTest2015.mdb';
    myConn.LoginPrompt := false;
    myConn.Open();

    myCom := TFDCommand.Create(nil);
    myCom.Connection := myConn;
    myCom.CommandText.Clear();
    myCom.CommandText.Add(sql);
    myCom.Execute();

    // myConn.ExecSQL(sql); {这样也是可行的}

    myConn.Close();
    myConn.Free();

    end;

    以下的方法也行

    procedure TForm2.btnTestClick(Sender: TObject);
    const
    strInsert = 'Insert Into tpUsers(userName,userPwd) VALUES (:name,:age)';
    var
    i : Integer;
    begin
    con1.Params.DriverID :='MSAcc';
    con1.Params.Database :='D:Test2015.mdb';
    con1.LoginPrompt := false;
    con1.Open();

    con1.ExecSQL(strInsert,['aaa','111']);
    con1.ExecSQL(strInsert,['bbb','222']);
    con1.ExecSQL(strInsert,['ccc','333']);
    con1.ExecSQL(strInsert,['ddd','444']);
    con1.ExecSQL(strInsert,['eee','555']);
    con1.ExecSQL(strInsert,['fff','666']);
    con1.ExecSQL(strInsert,['ggg','777']);

    end;

  • 相关阅读:
    combiner中使用状态模式
    了解Shell
    优秀工具推荐
    linux安装weblogic10.3
    FastDFS上传下载(上)
    java压缩工具类
    06链表
    05数组
    04时间复杂度
    03复杂度
  • 原文地址:https://www.cnblogs.com/LongHuaiYu/p/4835212.html
Copyright © 2011-2022 走看看