Qt/C++ 数据库SQL 增删改查 语句示例

注:文中例子均使用QSQLITE

一,  
QSqlQuery query;query.prepare(QString("INSERT INTO playList%1(songname,songurl,duration)"
                          "VALUES (:songname, :songurl,:duration)").arg(m_objIndex));
    query.bindValue(":songname", songname);
    query.bindValue(":songurl", url);
    query.bindValue(":duration", dur);
    query.exec(); 



二,
 
  
 QSqlQuery query;
        query.prepare(QString("DELETE FROM playlistname WHERE listname = ?"));
        query.addBindValue(name);
         query.exec();




三,
 query.prepare("update playlistname set listname = ? where listname = ?");
    query.addBindValue(newname);
    query.addBindValue(oldname);
    query.exec();




 
  
 
  
 
  
 
  
四,
 
  
QSqlQuery query1(QString("SELECT * FROM playList%1").arg(m_objIndex));
    int fieldNo = query1.record().indexOf("songname");
    while (query1.next()) {
        QString name = query1.value(fieldNo).toString();
          list1<
    }

mfc的
常用SQL语句
查询语句sql.Format("select * from xsxx where name='%s'",m_user1)
表示从 xsxx表中 选择 name=m_user1这一列 
添加语句
sql.Format("insert into xsxx(name,sex,age,num) values('%s','%s','%s','%s')",m_user1,m_user2,m_user3,m_user4);
删除语句
sql.Format("delete from xsxx where name='%s'",m_user);
修改语句
sql.Format("update xsxx set num='%s',age='%s',sex='%s' where name='%s'",m_user4,m_user3,m_user2,m_user1);

 
  
 
  
powered by:小乌龟在大乌龟背上 
  

 更多文章: http://blog.csdn.net/what951006

你可能感兴趣的:(Qt项目实现技术记录)