首页 > 新闻系统 > 编程天地 > 文章正文

Delphi2007中用DbExpress连接MySql的例子

2008-04-18 08:56:47 来源:中国自学编程网 作者:佚名 点击:

新建数据库/**//*
MySQL Data Transfer
Source Host: localhost
Source Database: blog
Target Host: localhost
Target Database: blog
Date: 2008/04/15 16:18:41
*/

SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for posts
-- ----------------------------
CREATE TABLE `posts` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `title` varchar(50) default NULL,
  `body` text,
  `created` datetime default NULL,
  `modified` datetime default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records 
-- ----------------------------
INSERT INTO `posts` VALUES (’1’, ’The title’, ’This is the post body.’, ’2008-04-08 11:51:46’, null);
INSERT INTO `posts` VALUES (’2’, ’A title once again’, ’And the post body follows.’, ’2008-04-08 11:51:46’, null);
INSERT INTO `posts` VALUES (’3’, ’Title strikes back’, ’This is really exciting! Not.’, ’2008-04-08 11:51:46’, null);

Delphi2007中新建工程,页面上追加TSimpleDataSet及TDataSource控件。

然后做如下设置

 

字段直接可以拉到页面上的,如下:

设置各个控件间的DataSource属性。后台代码:

使用 DbExpress 的时候总感觉很别扭。网上也有很多人说这套组件有潜在BUG存在。不知道是不是真的有李维大师所说的那样好。

注意:关于事务:使用StartTransaction方法的话需要用到TTransactionDesc类,这需要在开头uses部追加SqlExpr。

如果换成BeginTransaction方法的话需要用到TDBXTransaction类,这需要在开头uses部追加DBXCommon。

从警告信息可以判断,Delphi2007已经开始不推荐使用StartTransaction方法做事务处理了。


精彩推荐
焦点大图推荐
本类热门文章

论坛美图

广告联系 | 版权说明 | 意见建议 | 加入收藏 | 军网站群 [ 军软件园 - 军软件商城 - 军软件园论坛 ]

电信与信息服务业务经营许可证:京ICP证050203