在Qt中使用資料庫的常見報錯

2021-10-01 14:39:41 字數 898 閱讀 4976

qsqlquery::value: not positioned on a valid record

query.

prepare

("select id,name from employee where name like :inputname");

query.

bindvalue

(":inputname"

,str)

;query.

exec()

;// qstring namestr=query.value(1).tostring(); //如果這句放在這裡的話出現上述錯誤

if(query.

first()

)

解決方法:qsqlquery返回的資料集,record是停在第一條記錄之前的。所以,你獲得資料集後,必須執行next()或first()到第一條記錄,這時候record才是有效的。否則,exec完直接value肯定報這個錯.

error: fail to create table. qsqlerror(-1, 「driver not loaded」, 「driver not loaded」)

qsqldatabase db;

db = qsqldatabase:

:database

("first");

qsqlquery sql_query

(db)

;

解決方法:報錯原因是因為你建立的qsqlquery物件沒有和前邊的qsqldatabase物件關聯起來,所以報錯「裝置無法載入」。在初始化qsqlquery物件的時候 qsqlquery sql_query(db),進行關聯就可以了。

資料庫常見報錯ORA 及常見問題

1 ora 02270 此列列表的唯一關鍵字或主鍵不匹配 foreign key a references c b 外來鍵參考的表c中的鍵b沒有指定為主鍵 2 where後的字段 字元型之類要加 int型之類不用加 update s set age 99 where s 03111160 updat...

在Qt中使用SQLite資料庫

sqlite sql 是一款開源輕量級的資料庫軟體,不需要server,可以整合在其他軟體中,非常適合嵌入式系統。qt5以上版本可以直接使用sqlite qt自帶驅動 引入sql模組 在qt專案檔案 pro檔案 中,加入sql模組 qt sql include include include檢查連線...

QT中使用MySQL資料庫

1.鏈結mysql 首先正確安裝mysql資料庫。然後將libmysql.lib檔案放在qt安裝路徑下的對應編譯器的lib資料夾下,如f software qt5.9.5 5.9.5 mingw53 32 lib。將libmysql.dll檔案放在qt安裝路徑對應編譯器的bin資料夾下。最後可正常鏈...