我想用delphi编写一个程序,在sql server 2000中建立数据库,这个我知道简单,直接写sql语句就行.但在delphi程序里还设了2个edit对话框。我要在新建的数据库中新建用户,用户名和密码在delphi的程序中的两个edit对话框中指定,而不是在企业管理器窗口中操作!!这个怎么实现噢?谢谢!! 

解决方案 »

  1.   

    用adoconnect连到sqlserver,指定adoquery的connection
        with adoquery do
        begin
           close;
           SQL.clear;
           sql.add('xx ');  xx-->  sqlserver中建立用户的sql语句
           ExecSQL;
        end;
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      with adoquery1 do
      begin
        Close;
        SQL.Text:='EXEC sp_addlogin '+Quotedstr(edtUser.Text)+','+Quotedstr(edtPass.Text)+','+Quotedstr('Pubs');
        ExecSQL;
        Close;
        SQL.Text:='EXEC sp_grantdbaccess '+Quotedstr(edtUser.Text);
        ExecSQL;
        Close;
        SQL.Text:='EXEC sp_addrolemember '+Quotedstr('db_owner')+', '+Quotedstr(edtUser.Text);
        ExecSQL;
      end;
    end;