SQLite合并两个表
Qt ComboBox : SQLite Merge Two Table
我需要一些帮助。这是我的普通组合框的代码,它将通过选择客户ID来显示客户信息。如何从其他表(LOAN)显示数据& &;还可以在组合框上按客户id从CUSTOMER表中获取信息。
void LoanRequest::on_comboBox_custID_activated(const QString &arg1)
{
Login conn;
if (!conn.connOpen())
{
qDebug()<<"Failed to open the database.";
return;
}
conn.connOpen();
QSqlQuery qry;
if(qry.exec("SELECT * FROM CUSTOMER WHERE Cust_ID='"+arg1+"'"))
{
//database table, my 2 table that i want to merge
//LOAN : loanid, loan_type, custid,loan_status
//CUSTOMER : custid, custname, custic,custaddress, custtelno
while(qry.next())
{
ui->label_name->setText(qry.value(2).toString());
ui->label_icno->setText(qry.value(3).toString());
ui->label_telno->setText(qry.value(5).toString());
}
}
else
{
QMessageBox::critical(this,tr("Error"),qry.lastError().text());
}
conn.connClose();
}
试试这样:
if(qry.exec("SELECT CUSTOMER.custname,
CUSTOMER.custic,CUSTOMER.custtelno,LOAN.loanid
FROM CUSTOMER JOIN LOAN WHERE CUSTOMER.custid = LOAN.custid
AND Cust_ID='"+arg1+"'"))
{
//database table, my 2 table that i want to merge
//LOAN : loanid, loan_type, custid,loan_status
//CUSTOMER : custid, custname, custic,custaddress, custtelno
while(qry.next())
{
ui->label_name->setText(qry.value(2).toString());
ui->label_icno->setText(qry.value(3).toString());
ui->label_telno->setText(qry.value(5).toString());
}
}
相关文章:
- 在声明中合并两个常量"std::set"(不是在运行时)
- 在C++中合并两个库
- 为什么在排序链表上的这种合并实现总是将两个列表都设置为 NULL,而只有一个应该设置一个列表?
- 将两个 cpp 文件合并为一个 cpp 文件
- 合并两个排序链表时运行时出错
- 在 C++ 中合并两个排序链表
- 我如何根据 c++ 中的行合并两个 2D 数组
- C++ 如何将两个 makefile 对象目标规则(位于另一个文件夹中)合并到一个目标/规则中?
- 如何在Qt中合并/追加/添加两个用于线程的模型?
- 将两个列表合并为一个蛇形列表
- 使用运算符+将两个已排序的链表合并到位
- C++合并两个内存块?
- C++ 超载 += 用于两个袋子的合并,返回类型为空隙
- 两个 cin / cout 语句合并为一个
- 将两个 1D 直方图合并为一个
- 如何在C 中合并两个向量
- 如何合并两个双重链接列表(访问下一个链接)
- 合并两个排序的链表
- 如何修复合并两个C++数组时'Invalid Pointer'
- 如何合并两个A和B类以定义C 中抽象类的功能