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


    // 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;
    

      

  • 相关阅读:
    IE10无法打开,需要管理员权限才能打开
    Windows Server 2012 离线安装.NET2.03.5的方法
    Windows Server 2013 安装zune 4.8中文版
    微软发布Visual Studio 2012 Update 2
    禁止视频网站使用Flash P2P上传
    Windows Server 2012 + Firefox + Flash = Crash 崩溃的解决方法
    我的网站,求友情链接
    [zz]ObjectiveC 内存管理精髓
    限时免费抢!正版卡巴斯基安全部队2011激活码1年
    微软Windows 7 SP1 RC 官方已经提供下载
  • 原文地址:https://www.cnblogs.com/sail2000/p/7517466.html
Copyright © 2020-2023  润新知