QtÊý¾Ý¿â£¨Èý£©ÀûÓÃQSqlQueryÀàÖ´ÐÐSQLÓï¾ä£¨Ò»£©
±¾ÎÄÕÂÔ´´ÓÚwww.yafeilinux.com ×ªÔØÇë×¢Ã÷³ö´¦¡£
SQL¼´½á¹¹»¯²éѯÓïÑÔ£¬ÊǹØÏµÊý¾Ý¿âµÄ±ê×¼ÓïÑÔ¡£Ç°ÃæÒѾÌáµ½£¬ÔÚQtÖÐÀûÓÃQSqlQueryÀàʵÏÖÁËÖ´ÐÐSQLÓï¾ä¡£ÐèҪ˵Ã÷£¬ÎÒÃÇÕâÀïÖ»ÊÇQt½Ì³Ì£¬¶ø·ÇרҵµÄÊý¾Ý¿â½Ì³Ì£¬ËùÒÔÎÒÃDz»»á¶ÔÊý¾Ý¿âÖеÄһЩ֪ʶ½øÐÐÉîÈë½²½â£¬ÏÂÃæÖ»ÊǶÔ×î³£Óõö֪ʶµã½øÐн²½â¡£
ÎÒÃÇÏÂÃæÏȽ¨Á¢Ò»¸ö¹¤³Ì£¬È»ºó½²½âËĸö֪ʶµã£¬·Ö±ðÊÇ£º
Ò»£¬²Ù×÷SQLÓï¾ä·µ»ØµÄ½á¹û¼¯¡£
¶þ£¬ÔÚSQLÓï¾äÖÐʹÓñäÁ¿¡£
Èý£¬Åú´¦Àí²Ù×÷¡£
ËÄ£¬ÊÂÎñ²Ù×÷¡£
ÎÒÃÇн¨Qt4 Gui Application¹¤³Ì£¬ÎÒÕâÀ﹤³ÌÃûΪquery £¬È»ºóÑ¡ÖÐQtSqlÄ£¿é£¬Base classÑ¡QWidget¡£¹¤³Ì½¨ºÃºó£¬Ìí¼ÓC++ Header File £¬ÃüÃûΪconnection.h £¬¸ü¸ÄÆäÄÚÈÝÈçÏ£º
#ifndef CONNECTION_H
#define CONNECTION_H
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlQuery>
static bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase(“QSQLITE”);
db.setDatabaseName(“:memory:”);
if (!db.open()) {
QMessageBox::critical(0, qApp->tr(“Cannot open database”),
qApp->tr(“Unable to establish a database connection.”
), QMessageBox::Cancel);
return false;
}
QSqlQuery query;
query.exec(“create table student (id int primary key, ”
“name varchar(20))”);
query.exec(“insert into student values(0, ‘first’)”);
query.exec(“insert into student values(1, ’second’)”);
query.exec(“insert into student values(2, ‘third’)”);
&
Ïà¹ØÎĵµ£º
--·ÃÎʲ»Í¬µçÄÔÉϵÄÊý¾Ý¿â
--Èç¹û¾³£·ÃÎÊ»òÊý¾ÝÁ¿´ó,½¨ÒéÓÃÁ´½Ó·þÎñÆ÷
--´´½¨Á´½Ó·þÎñÆ÷
exec sp_addlinkedserver 'srv_lnk','','SQLOLEDB','Ô¶³Ì·þÎñ ......
SQLÖÐNµÄ×÷ÓÃ?
exec sp_executesql N'SELECT TOP 1 ISNULL(vDefine1,'''') AS vMonth, dtBegin, dtEnd from SM_ActMonth WHERE vActID=@P1 AND bCarryForward=@P2 ORDER BY iListID DESC
', N'@P1 varchar(3),@P2 bit', '001', 1
exec sp_executesql N'SELECT * from KEHU WHERE KHDM>=@P1 AND ZK=@P2',N'@P1 VARCHAR ......
´´½¨Ò»ÕÅ±í£¬Ö±½ÓÔÚ±íÁÐÉϰó¶¨Ä¬ÈÏÖµ
CREATE TABLE hello
(
Id_P int PRIMARY KEY,
Firstname varchar(50) DEFAULT 'Bush',
Lastname varchar(50) DEFAULT 'Green',
Address varchar(50) DEFAULT 'China',
City varchar(50) DEFAULT 'beijing'
)
²åÈëÒ»ÌõÐÅÏ¢
INSERT INTO hello(Id_P) values(01)
½á¹ûÊÇ
×ܽ ......
/*
±êÌ⣺һ¸öÏîÄ¿Éæ¼°µ½µÄ50¸öSqlÓï¾ä(ÕûÀí°æ)
×÷Õߣº°®Ð¾õÂÞ.ع»ª(Ê®°ËÄê·çÓê£¬ÊØµÃ±ùɽѩÁ«»¨¿ª)
ʱ¼ä£º2010-05-10
µØµã£ºÖØÇ캽ÌìְҵѧԺ
˵Ã÷£ºÒÔÏÂÎåÊ®¸öÓï¾ä¶¼°´ÕÕ²âÊÔÊý¾Ý½øÐйý²âÊÔ£¬×îºÃÿ´ÎÖ»µ¥¶ÀÔËÐÐÒ»¸öÓï¾ä¡£
ÎÊÌâ¼°ÃèÊö£º
--1.ѧÉú±í
Student(S#,Sname,Sage,Ssex) --S# ѧÉú±àºÅ,Sname ѧÉúÐÕÃû,S ......