Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
请提示我,如何使用 Trolltech Qt 4.x SQL 类将空值插入表中?QSqlQuery,我猜,或者来自 QtNetwork 的其他内容。作为它的类比,在 .NET 中有一个System.DbNull类,它代表 sql NULL。
QSqlQuery
System.DbNull
我应该为某个对象的属性使用什么类型,它可以同时保存空值和QString?在 C# 中,我可以使用System.Object.
QString
System.Object
从QSqlQuery::addBindValue文档:
QSqlQuery::addBindValue
要绑定 NULL 值,请使用 null QVariant;例如,如果要绑定字符串,请使用 QVariant(QVariant::String)。
回答第二个问题,QString可以为空。
问题是针对 QT 4,但我认为值得一提的是,在 QT 5 中您只需传递一个 NULL 值。