zoukankan      html  css  js  c++  java
  • DelPhi连接数据库方式

    一、SQL Server 2000 的连接数据库
    1.无密码连接
    SQLL:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=test;Data Source=192.168.0.23';                                      //catalog 指数据库名称 datasource 指 计算机名称,也
    Data.ADOCnn.ConnectionString:=SQLL;        //可以是ip地址
    Data.ADOCnn.Connected:=false;
    Data.ADOCnn.LoginPrompt:=false;
    try
       Data.ADOCnn.Connected:=true;
    except                                          //连接失败处理
        begin
         MessageBox(0,'连接数据库失败!','提示',64);
         Application.Terminate;
        end;
    end;
    2.有密码连接 (密码为123)
       SQLL:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;PassWord=123;Initial Catalog=test;Data Source=192.168.0.23'; 

    二、Access 数据库的连接
    1.无密码,决对路径连接
    AdoConnection1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source= '
                                            + OpenDialog1.FileName; //绝对路径,这里是用打开文件的路径
          AdoConnection1.LoginPrompt := False;
          AdoConnection1.Connected := True;

    2. 有密码,相对路径连接
    pwd:='123';
    SQLL:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+
             extractfilepath(application.ExeName)+'db1.mdb'+
             ';Persist Security Info=False;Jet OLEDB:Database Password="'+pwd+'"';
    Form1.ADOConn.Connected:=false;
    Form1.ADOConn.LoginPrompt:=false;
    Form1.ADOConn.ConnectionString:=SQLL;
    try
        Form1.ADOConn.Connected:=true;                 //连接数据库
    except
        begin
         MessageBox(0,'连接数据库失败!','提示',64);
         Application.Terminate;
    end;
    end;
    三、选择数据库连接(access)
    procedure TFormMainWindow.FormCreate(Sender: TObject);
    begin
    FTableList := TStringList.Create;
    end;

    //按钮点击事件

    OpenDialog1.Filter := '数据库文件(*.*)';
    if OpenDialog1.Execute then
    begin
        try
          if AdoConnection1.Connected then AdoConnection1.Connected := False;
          AdoConnection1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source= '
                                            + OpenDialog1.FileName;
          AdoConnection1.LoginPrompt := False;
          AdoConnection1.Connected := True;
          AdoConnection1.GetTableNames(FTableList);           //FTableList : Tstings
          CboTables.Items := FTableList;                                 //CboTables:combobox
  • 相关阅读:
    Linux命令总结--grep命令
    Linux命令总结--sed命令
    python函数--enumerate()方法
    python函数--index()方法
    在objc项目中使用常量的最佳实践
    iOS 开发 初级:应用内购买 In-App Purchase
    CFUUIDRef和CFStringRef-生成唯一标识符
    保留你的dSYM文件
    xcode 环境,多工程联编设置【转】
    ld: symbol dyld_stub_binding_helper not found, normally in crt1.o/dylib1.o/bundle1.o for architecture i386
  • 原文地址:https://www.cnblogs.com/weihengblogs/p/3200400.html
Copyright © 2011-2022 走看看