delphi如何连接到sql服务器,并验证SA的密码,验证通过以后,如何在SQL服务器上,新建一个数据库a,并在数据库a上新建一个表b,最好是给出源码?跪求!!

解决方案 »

  1.   

    adocommand1.ConnectionString:='Provider=SQLOLEDB.1;Password=sa'+
                                      ';Persist Security Info=True;User ID=sa'+
                                      ';Initial Catalog=Master'+
                                      ';Data Source=127.0.0.1';
    adocommand1.CommandText:='use master';
    adocommand1.Execute;
    adocommand1.CommandText:='....';//创建数据库
    adocommand1.Execute;
      

  2.   

    已前的建庫你試試吧
    CREATE DATABASE database_name
    [ ON [PRIMARY]
            [ <filespec> [,...n] ]
            [, <filegroup> [,...n] ]
    ]
    [ LOG ON { <filespec> [,...n]} ]
    [ FOR LOAD | FOR ATTACH ]<filespec> ::=  ( [ NAME = logical_file_name, ]
      FILENAME = 'os_file_name'
      [, SIZE = size]
      [, MAXSIZE = { max_size | UNLIMITED } ]
      [, FILEGROWTH = growth_increment] ) [,...n]<filegroup> ::=FILEGROUP filegroup_name <filespec> [,...n] 
    --------------------------------------------------
     以下是建表 
    { Don't overwrite an existing table }if not Table1.Exists then begin
      with Table1 do begin
        { The Table component must not be active }
        Active := False;  
        { First, describe the type of table and give }
        { it a name }
        DatabaseName := 'DBDEMOS';
        TableType := ttParadox;
        TableName := 'CustInfo';
        { Next, describe the fields in the table }
        with FieldDefs do begin
          Clear;
          with AddFieldDef do begin        Name := 'Field1';
            DataType := ftInteger;
            Required := True;
          end;
          with AddFieldDef do begin
            Name := 'Field2';
            DataType := ftString;
            Size := 30;
          end;
        end;
        { Next, describe any indexes }
        with IndexDefs do begin
          Clear;
          { The 1st index has no name because it is
          { a Paradox primary key }
          with AddIndexDef do begin        Name := '';
            Fields := 'Field1';
            Options := [ixPrimary];
          end;
          with AddIndexDef do begin
            Name := 'Fld2Indx';
            Fields := 'Field2';
            Options := [ixCaseInsensitive];
          end;
        end;
        { Call the CreateTable method to create the table }
        CreateTable;
      end;
    end; 
    --------------------------------------
    在DELPHI幫助裡可以找到相關的資料