白雪公主的后妈 2023-01-19 18:58 采纳率: 26.3%
浏览 67
已结题

mfc与数据库交换过程中参数不足

显示参数不足,但是对应的数据库还有程序对应的个数都一样,找不出问题。最后运行后可以修改但是后边刷新数据库没有用,应该是sql语句有问题,有没有人会的,教教

img

img


void BEILIAO::OnBnClickedButton3()//修改

{
// TODO: 在此添加控件通知处理程序代码

CString strd1, strd2, strId, strd1s, strd1x, strd2s, strd2x;

GetDlgItemText(IDC_EDIT4, strId);

GetDlgItemText(IDC_EDIT1, strd1);

GetDlgItemText(IDC_EDIT3, strd1s);

GetDlgItemText(IDC_EDIT5, strd1x);

GetDlgItemText(IDC_EDIT2, strd2);

GetDlgItemText(IDC_EDIT6, strd2s);

GetDlgItemText(IDC_EDIT8, strd2x);

if (strId.IsEmpty()) {
MessageBox(_T("请输入要修改的编号"), _T("修改操作"), MB_ICONWARNING);

return;

}

// 2、执行 SQL语句

CString strSql = _T("update beiliao set ");

//strSql += _T("beiliao.[d1]=\'") + strd1 + _T("\'");

//strSql += _T(",beiliao.[d1s]=\'") + strd1s + _T("\'");

//strSql += _T(",beiliao.[d1x]=\'") + strd1x + _T("\'");

//strSql += _T(",beiliao.[d2]=\'") + strd2 + _T("\'");

//strSql += _T(",beiliao.[d2s]=\'") + strd2s + _T("\'");

//strSql += _T(",beiliao.[d2x]=\'") + strd2x + _T("\'");

strSql += _T("beiliao.[d1]=") + strd1;

strSql += _T(",beiliao.[d1s]=") + strd1s;

strSql += _T(",beiliao.[d1x]=") + strd1x;

strSql += _T(",beiliao.[d2]=") + strd2;

strSql += _T(",beiliao.[d2s]=") + strd2s;

strSql += _T(",beiliao.[d2x]=") + strd2x;

strSql += _T(" where beiliao.[ID]=") + strId;

MessageBox(strSql);

try {
m_db.ExecuteSQL(strSql);

}

catch (CDBException* e) {
MessageBox(_T("" + e->m_strError), _T("修改操作"), MB_ICONWARNING);

return;

}

// 3、更新列表框的显示

strSql = _T("select beiliao.[ID], beiliao.[d1], beiliao.[d1s] , beiliao.[d1x], beiliao.[strd2] , beiliao.[strd2s], beiliao.[strd2x] from beiliao order by beiliao.[ID] asc;");

DispBySql(strSql);

}
  • 写回答

3条回答 默认 最新

  • m0_54204465 2023-01-19 19:15
    关注

    这是一段 C++ 代码,用于在 MFC 中修改数据库中的记录。它读取了若干输入框中的文本,然后拼接成一条 SQL 语句,用于修改数据库中的记录。你问的“参数不足”的问题可能是由于某个输入框中没有输入文本导致的。需要注意的是,这段代码里有一些语句被注释掉了。

    评论

报告相同问题?

问题事件

  • 系统已结题 1月27日
  • 赞助了问题酬金15元 1月19日
  • 创建了问题 1月19日