具体要求如下:
1.通过一个文本框输入数据库名,通过一个按钮来建立数据库,检查在数据库是否有相同的数据库名,如果有则提示,如果没有则建立该数据库。
2.在该数据库建立后,建立一个含有 ‘id’,'name','age'字段的表,表名为table1.
3。最好能给写个小程序。
Email:[email protected]

解决方案 »

  1.   

    单元源码如下:unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Buttons, DB, ADODB;type
      TForm1 = class(TForm)
        ADOQuery: TADOQuery;
        ADOConnection1: TADOConnection;
        BitBtn1: TBitBtn;
        procedure BitBtn1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
    ADOConnection1.Close;
    ADOConnection1.ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=master;Data Source=. ';ADOQuery.Close;
    ADOQuery.SQL.Text:='IF EXISTS (SELECT * FROM sysdatabases WHERE name = ''MyMEMO'')  SELECT 1 AS HAVE ELSE SELECT 0 AS HAVE ';
    ADOQuery.Open;
    if ADOQuery.FieldByName('HAVE').AsInteger=1 then
    begin
      ShowMessage('存在');  Abort;
    end;ADOQuery.Close;
    ADOQuery.SQL.Text:=' create database MyMEMO ';
    ADOQuery.ExecSQL;
    ADOConnection1.Close;
    ADOConnection1.ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=MyMEMO;Data Source=. ';ADOQuery.SQL.Text:='create table Table_1 (   '+
      '   id                   int                  identity, '+
      '   name                 varchar(10)          null, '     +
      ' age                  int                  null, '+
      '   constraint PK_TABLE_1 primary key  (id) ) ';
     ADOQuery.ExecSQL;end;end.窗体属性如下:
    object Form1: TForm1
      Left = 192
      Top = 107
      Width = 696
      Height = 480
      Caption = 'Form1'
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'MS Sans Serif'
      Font.Style = []
      OldCreateOrder = False
      PixelsPerInch = 96
      TextHeight = 13
      object BitBtn1: TBitBtn
        Left = 168
        Top = 216
        Width = 75
        Height = 25
        Caption = 'BitBtn1'
        TabOrder = 0
        OnClick = BitBtn1Click
      end
      object ADOQuery: TADOQuery
        Connection = ADOConnection1
        Parameters = <>
        Left = 224
        Top = 40
      end
      object ADOConnection1: TADOConnection
        ConnectionString = 
          'Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initi' +
          'al Catalog=master;Data Source=.'
        Provider = 'SQLOLEDB.1'
        Left = 88
        Top = 32
      end
    end
    在Delphi7 下调试通过!
      

  2.   

    to madyak(无天) :你好 
      我也用的是d7,能不能把例子程序给我发一份啊?
      

  3.   

    邮件的标题:
    源程序附件:Demo.rar之前还有一封空邮件:
    标题:已写贴上!建库源码!如有问题请联系!//**********//看你现在有没有收到带有附件的那封!