sql="SELECT * FROM DHCW_SHEET where 1=1 ";
if(!vssorder.IsEmpty())
{
str.Format(_T("and 序号='%s'"),vssorder);
sql+=str;
try
{
hr =m_pRecordset->Open((_variant_t)sql
,_variant_t((IDispatch*)m_pConnection,true) /*m_pConnection的指针地址*/
,adOpenStatic
,adLockOptimistic
,adCmdText);
_variant_t vsorder,vsname,vscard,vstype,vsprice /*定义列名中间变量 */
,vsgross,vstare,vssuttle,vstotal,vsaccount,vsarrearage
,vswhether,vsadata,vscdata,vsremark;
vsorder = m_pRecordset->GetCollect(_T("序号"));
vsname = m_pRecordset->GetCollect(_T("姓名"));
vscard = m_pRecordset->GetCollect(_T("车牌号"));
vstype = m_pRecordset->GetCollect(_T("货物类型"));
vsprice = m_pRecordset->GetCollect(_T("单价"));
vsgross = m_pRecordset->GetCollect(_T("毛重"));
vstare = m_pRecordset->GetCollect(_T("皮重"));
vssuttle = m_pRecordset->GetCollect(_T("净重"));
vstotal = m_pRecordset->GetCollect(_T("总价"));
vsaccount = m_pRecordset->GetCollect(_T("已付金额"));
vsarrearage = m_pRecordset->GetCollect(_T("未付金额"));
vswhether = m_pRecordset->GetCollect(_T("是否付清"));
vsadata = m_pRecordset->GetCollect(_T("到货时间"));
vscdata = m_pRecordset->GetCollect(_T("结算时间"));
vsremark = m_pRecordset->GetCollect(_T("备注"));
int iItemCount=m_search_list.GetItemCount();
m_search_list.InsertItem(iItemCount,_T(""));
m_search_list.SetItemText(iItemCount,0,(_bstr_t)vsorder);
m_search_list.SetItemText(iItemCount,1,(_bstr_t)vsname);
m_search_list.SetItemText(iItemCount,2,(_bstr_t)vscard);
m_search_list.SetItemText(iItemCount,3,(_bstr_t)vstype);
m_search_list.SetItemText(iItemCount,4,(_bstr_t)vsprice);
m_search_list.SetItemText(iItemCount,5,(_bstr_t)vsgross);
m_search_list.SetItemText(iItemCount,6,(_bstr_t)vstare);
m_search_list.SetItemText(iItemCount,7,(_bstr_t)vssuttle);
m_search_list.SetItemText(iItemCount,8,(_bstr_t)vstotal);
m_search_list.SetItemText(iItemCount,9,(_bstr_t)vsaccount);
m_search_list.SetItemText(iItemCount,10,(_bstr_t)vsarrearage);
m_search_list.SetItemText(iItemCount,11,(_bstr_t)vswhether);
m_search_list.SetItemText(iItemCount,12,(_bstr_t)vsadata);
m_search_list.SetItemText(iItemCount,13,(_bstr_t)vscdata);
m_search_list.SetItemText(iItemCount,14,(_bstr_t)vsremark);
//m_pRecordset->MoveNext();
//index2=0;
}
catch(_com_error e)
{
MessageBox(_T("读取数据库失败!"));
m_pConnection->RollbackTrans();
}
}
问题 :
我把ACCESS数据库的首列ID改名为序号,次列为姓名、车牌号等了,自动增长。
我希望按生成的序号来查询唯一的一行,以后可以加入修改代码
但是执行到
hr =m_pRecordset->Open((_variant_t)sql
,_variant_t((IDispatch*)m_pConnection,true)
,adOpenStatic
,adLockOptimistic
,adCmdText);
这里的时候就报错了,但是将序号换成姓名或车牌号并不报错
(下面会比本例多一条while(!m_pRecordset->adoEOF){}这个语句)
请问这是什么原因 怎么修改才能实现功能 按序号查询唯一一行