码迷,mamicode.com
首页 > 数据库 > 详细

Delphi X10.2 + FireDAC 使用 SQL 语句 INSERT

时间:2017-09-13 21:17:36      阅读:684      评论:0      收藏:0      [点我收藏+]

标签:stream   query   mit   rtt   .text   password   value   star   username   

// CREATE TABLE [tabusers](
// [id] INTEGER PRIMARY KEY AUTOINCREMENT,
// [username] CHAR NOT NULL,
// [userpwd] CHAR NOT NULL,
// [usernickname] CHAR,
// [useroffice] CHAR,
// [userprofiles] BLOB,
// [regdatetime] DATETIME,
// [userpermission] CHAR,
// [useronline] BOOLEAN,
// [usertablename] CHAR);

MainForm.Conn.StartTransaction;
UserManagerQuery.SQL.Clear;
UserManagerQuery.SQL.Text := ‘INSERT INTO tabusers(‘ + //
          ‘username, userpwd, usernickname, useroffice, userprofiles, regdatetime, userpermission, useronline, usertablename)‘
          + //
          ‘ VALUES (:username, :userpwd, :usernickname, :useroffice, :userprofiles, :regdatetime, :userpermission, :useronline, :usertablename)‘;

        UserManagerQuery.Params[0].AsString := edtUserName.Text;
        if Using_Default_Pwd then
          UserManagerQuery.Params[1].AsString := Default_Password
        else
          UserManagerQuery.Params[1].AsString :=
            MD5Print(MD5StringA(AnsiString(edtUserPwd.Text)));
        UserManagerQuery.Params[2].AsString := edtUserNickName.Text;
        UserManagerQuery.Params[3].AsString := edtUserOffice.Text;

        MS := TMemoryStream.Create;
        ImgUserProfiles.Picture.SaveToStream(MS);
        MS.Position := 0;
        UserManagerQuery.Params[4].LoadFromStream(MS, ftBlob);
        MS.Free;

        UserManagerQuery.Params[5].AsDateTime := Now;
        UserManagerQuery.Params[6].AsString   := edtUserPermission.Text;
        UserManagerQuery.Params[7].AsBoolean  := False;

        User_Count    := UserListBox.Items.Count;
        New_user_Name := ‘tab_user‘ + Format(‘%.3d‘, [User_Count]);;
        UserManagerQuery.Params[8].AsString := New_user_Name;

        UserManagerQuery.ExecSQL;
        MainForm.Conn.Commit;

        UserListBox.Items.Add(edtUserName.Text);

        try
          // CREATE TABLE "tab_user001"(
          // [ID] INTEGER PRIMARY KEY AUTOINCREMENT,
          // [aDate] DATE NOT NULL,
          // [aComments] CHAR,
          // [aProgress] CHAR,
          // [aNote01] CHAR,
          // [aNote02] CHAR);

          UserManagerQuery.SQL.Clear;
          strSQL := ‘CREATE TABLE ‘ + New_user_Name + ‘ (‘ +
            ‘[ID] INTEGER PRIMARY KEY AUTOINCREMENT,‘ + ‘[aDate] DATE NOT NULL,‘
            + ‘[aComments] CHAR,‘ + ‘[aProgress] CHAR,‘ + ‘[aNote01] CHAR,‘ +
            ‘[aNote02] CHAR)‘;
          UserManagerQuery.Command.Prepare(strSQL);//注意这里不能用 ExecSQL / Open() / OpenOrExecute 这类东东
          UserManagerQuery.Execute();

        except
          on E: Exception do
          begin
            ShowMessage(E.Message);
          end;
        end;

  

Delphi X10.2 + FireDAC 使用 SQL 语句 INSERT

标签:stream   query   mit   rtt   .text   password   value   star   username   

原文地址:http://www.cnblogs.com/sail2000/p/7517466.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!