📄 xuqiuvsduixiang4.cpp
字号:
cindex2);
if(!OpenRecordSet(m_pRecordset,strSQL3))
{
AfxMessageBox("没有成功打开数据表");
return;
}
//上述准备完毕,下面开始插入内容
try
{
m_xishu=atoi(VariantToCString(m_pRecordset->GetCollect("f")));
UpdateData(false);
//更新数据库
m_pRecordset->Update();
}
catch(_com_error e)
{
CString strError;
strError.Format("警告: 插入信息时发生异常。 错误信息: %s",\
e.ErrorMessage());
AfxMessageBox(strError);
}
m_pRecordset->Close();
m_pRecordset=NULL;
break;
case 7:
strSQL3.Format("select g from 需求和比较对象关系表4 where ID='%s' \
",\
cindex2);
if(!OpenRecordSet(m_pRecordset,strSQL3))
{
AfxMessageBox("没有成功打开数据表");
return;
}
//上述准备完毕,下面开始插入内容
try
{
m_xishu=atoi(VariantToCString(m_pRecordset->GetCollect("g")));
UpdateData(false);
//更新数据库
m_pRecordset->Update();
}
catch(_com_error e)
{
CString strError;
strError.Format("警告: 插入信息时发生异常。 错误信息: %s",\
e.ErrorMessage());
AfxMessageBox(strError);
}
m_pRecordset->Close();
m_pRecordset=NULL;
break;
case 8:
strSQL3.Format("select h from 需求和比较对象关系表4 where ID='%s' \
",\
cindex2);
if(!OpenRecordSet(m_pRecordset,strSQL3))
{
AfxMessageBox("没有成功打开数据表");
return;
}
try
{
m_xishu=atoi(VariantToCString(m_pRecordset->GetCollect("h")));
UpdateData(false);
//更新数据库
m_pRecordset->Update();
}
catch(_com_error e)
{
CString strError;
strError.Format("警告: 插入信息时发生异常。 错误信息: %s",\
e.ErrorMessage());
AfxMessageBox(strError);
}
m_pRecordset->Close();
m_pRecordset=NULL;
break;
case 9:
strSQL3.Format("select i from 需求和比较对象关系表4 where ID='%s' \
",\
cindex2);
if(!OpenRecordSet(m_pRecordset,strSQL3))
{
AfxMessageBox("没有成功打开数据表");
return;
}
try
{
m_xishu=atoi(VariantToCString(m_pRecordset->GetCollect("i")));
UpdateData(false);
//更新数据库
m_pRecordset->Update();
}
catch(_com_error e)
{
CString strError;
strError.Format("警告: 插入信息时发生异常。 错误信息: %s",\
e.ErrorMessage());
AfxMessageBox(strError);
}
m_pRecordset->Close();
m_pRecordset=NULL;
break;
case 10:
strSQL3.Format("select j from 需求和比较对象关系表4 where ID='%s' \
",\
cindex2);
if(!OpenRecordSet(m_pRecordset,strSQL3))
{
AfxMessageBox("没有成功打开数据表");
return;
}
try
{
m_xishu=atoi(VariantToCString(m_pRecordset->GetCollect("j")));
UpdateData(false);
//更新数据库
m_pRecordset->Update();
}
catch(_com_error e)
{
CString strError;
strError.Format("警告: 插入信息时发生异常。 错误信息: %s",\
e.ErrorMessage());
AfxMessageBox(strError);
}
m_pRecordset->Close();
m_pRecordset=NULL;
break;
default:break;
} //打开记录集 选择表名
}
else{}
}
void CxuqiuVSduixiang4::OnClickDatalist2()
{
UpdateData(true);//更新编辑框,并且将当前编辑框的数值赋给m_xishu
int index1=0,index2=0;
CString term1;
CString term2;
term1=m_list1.GetText();
term2=m_list2.GetText();
if(term1!="")
{
CString strSQL1;
strSQL1.Format("select * from 工程措施3 where 工程措施='%s' \
",\
term1
);
//打开记录集 选择表名
if(!OpenRecordSet(m_pRecordset,strSQL1))
{
AfxMessageBox("没有成功打开数据表");
return;
}
CString cindex1=VariantToCString(m_pRecordset->GetCollect("ID"));
index1=atoi(cindex1);
//关闭
m_pRecordset->Close();
m_pRecordset=NULL;
CString strSQL2;
strSQL2.Format("select * from 比较对象 where 比较对象='%s' \
",\
term2
);
//打开记录集 选择表名
if(!OpenRecordSet(m_pRecordset,strSQL2))
{
AfxMessageBox("没有成功打开数据表");
return;
}
CString cindex2=VariantToCString(m_pRecordset->GetCollect("ID"));
index2=atoi(cindex2);
//关闭
m_pRecordset->Close();
m_pRecordset=NULL;
// m_xishu=index1;
//UpdateData(false); //更新编辑框,但不将当前编辑框的数值赋给m_xishu
// AfxMessageBox(term1 + " "+ term2+" " + cindex1+ " " +cindex2);
CString strSQL3;
CString a;
switch(index1){
case 1:
strSQL3.Format("select a from 需求和比较对象关系表4 where ID='%s' \
",\
cindex2);
if(!OpenRecordSet(m_pRecordset,strSQL3))
{
AfxMessageBox("没有成功打开数据表");
return;
}
//a.Format("%d",m_xishu);
//上述准备完毕,下面开始插入内容
try
{
// m_pRecordset->PutCollect("a",_variant_t(a));
m_xishu=atoi(VariantToCString(m_pRecordset->GetCollect("a")));
UpdateData(false);
//更新数据库
m_pRecordset->Update();
}
catch(_com_error e)
{
CString strError;
strError.Format("警告: 插入信息时发生异常。 错误信息: %s",\
e.ErrorMessage());
AfxMessageBox(strError);
}
m_pRecordset->Close();
m_pRecordset=NULL;
break;
case 2:
strSQL3.Format("select b from 需求和比较对象关系表4 where ID='%s' \
",\
cindex2);
if(!OpenRecordSet(m_pRecordset,strSQL3))
{
AfxMessageBox("没有成功打开数据表");
return;
}
//上述准备完毕,下面开始插入内容
try
{
m_xishu=atoi(VariantToCString(m_pRecordset->GetCollect("b")));
UpdateData(false);
//更新数据库
m_pRecordset->Update();
}
catch(_com_error e)
{
CString strError;
strError.Format("警告: 插入信息时发生异常。 错误信息: %s",\
e.ErrorMessage());
AfxMessageBox(strError);
}
m_pRecordset->Close();
m_pRecordset=NULL;
break;
case 3:
strSQL3.Format("select c from 需求和比较对象关系表4 where ID='%s' \
",\
cindex2);
if(!OpenRecordSet(m_pRecordset,strSQL3))
{
AfxMessageBox("没有成功打开数据表");
return;
}
//上述准备完毕,下面开始插入内容
try
{
m_xishu=atoi(VariantToCString(m_pRecordset->GetCollect("c")));
UpdateData(false);
//更新数据库
m_pRecordset->Update();
}
catch(_com_error e)
{
CString strError;
strError.Format("警告: 插入信息时发生异常。 错误信息: %s",\
e.ErrorMessage());
AfxMessageBox(strError);
}
m_pRecordset->Close();
m_pRecordset=NULL;
break;
case 4:
strSQL3.Format("select d from 需求和比较对象关系表4 where ID='%s' \
",\
cindex2);
if(!OpenRecordSet(m_pRecordset,strSQL3))
{
AfxMessageBox("没有成功打开数据表");
return;
}
//上述准备完毕,下面开始插入内容
try
{
m_xishu=atoi(VariantToCString(m_pRecordset->GetCollect("d")));
UpdateData(false);
//更新数据库
m_pRecordset->Update();
}
catch(_com_error e)
{
CString strError;
strError.Format("警告: 插入信息时发生异常。 错误信息: %s",\
e.ErrorMessage());
AfxMessageBox(strError);
}
m_pRecordset->Close();
m_pRecordset=NULL;
break;
case 5:
strSQL3.Format("select e from 需求和比较对象关系表4 where ID='%s' \
",\
cindex2);
if(!OpenRecordSet(m_pRecordset,strSQL3))
{
AfxMessageBox("没有成功打开数据表");
return;
}
//上述准备完毕,下面开始插入内容
try
{
m_xishu=atoi(VariantToCString(m_pRecordset->GetCollect("e")));
UpdateData(false);
//更新数据库
m_pRecordset->Update();
}
catch(_com_error e)
{
CString strError;
strError.Format("警告: 插入信息时发生异常。 错误信息: %s",\
e.ErrorMessage());
AfxMessageBox(strError);
}
m_pRecordset->Close();
m_pRecordset=NULL;
break;
case 6:
strSQL3.Format("select f from 需求和比较对象关系表4 where ID='%s' \
",\
cindex2);
if(!OpenRecordSet(m_pRecordset,strSQL3))
{
AfxMessageBox("没有成功打开数据表");
return;
}
//上述准备完毕,下面开始插入内容
try
{
m_xishu=atoi(VariantToCString(m_pRecordset->GetCollect("f")));
UpdateData(false);
//更新数据库
m_pRecordset->Update();
}
catch(_com_error e)
{
CString strError;
strError.Format("警告: 插入信息时发生异常。 错误信息: %s",\
e.ErrorMessage());
AfxMessageBox(strError);
}
m_pRecordset->Close();
m_pRecordset=NULL;
break;
case 7:
strSQL3.Format("select g from 需求和比较对象关系表4 where ID='%s' \
",\
cindex2);
if(!OpenRecordSet(m_pRecordset,strSQL3))
{
AfxMessageBox("没有成功打开数据表");
return;
}
//上述准备完毕,下面开始插入内容
try
{
m_xishu=atoi(VariantToCString(m_pRecordset->GetCollect("g")));
UpdateData(false);
//更新数据库
m_pRecordset->Update();
}
catch(_com_error e)
{
CString strError;
strError.Format("警告: 插入信息时发生异常。 错误信息: %s",\
e.ErrorMessage());
AfxMessageBox(strError);
}
m_pRecordset->Close();
m_pRecordset=NULL;
break;
case 8:
strSQL3.Format("select h from 需求和比较对象关系表4 where ID='%s' \
",\
cindex2);
if(!OpenRecordSet(m_pRecordset,strSQL3))
{
AfxMessageBox("没有成功打开数据表");
return;
}
try
{
m_xishu=atoi(VariantToCString(m_pRecordset->GetCollect("h")));
UpdateData(false);
//更新数据库
m_pRecordset->Update();
}
catch(_com_error e)
{
CString strError;
strError.Format("警告: 插入信息时发生异常。 错误信息: %s",\
e.ErrorMessage());
AfxMessageBox(strError);
}
m_pRecordset->Close();
m_pRecordset=NULL;
break;
case 9:
strSQL3.Format("select i from 需求和比较对象关系表4 where ID='%s' \
",\
cindex2);
if(!OpenRecordSet(m_pRecordset,strSQL3))
{
AfxMessageBox("没有成功打开数据表");
return;
}
try
{
m_xishu=atoi(VariantToCString(m_pRecordset->GetCollect("i")));
UpdateData(false);
//更新数据库
m_pRecordset->Update();
}
catch(_com_error e)
{
CString strError;
strError.Format("警告: 插入信息时发生异常。 错误信息: %s",\
e.ErrorMessage());
AfxMessageBox(strError);
}
m_pRecordset->Close();
m_pRecordset=NULL;
break;
case 10:
strSQL3.Format("select j from 需求和比较对象关系表4 where ID='%s' \
",\
cindex2);
if(!OpenRecordSet(m_pRecordset,strSQL3))
{
AfxMessageBox("没有成功打开数据表");
return;
}
try
{
m_xishu=atoi(VariantToCString(m_pRecordset->GetCollect("j")));
UpdateData(false);
//更新数据库
m_pRecordset->Update();
}
catch(_com_error e)
{
CString strError;
strError.Format("警告: 插入信息时发生异常。 错误信息: %s",\
e.ErrorMessage());
AfxMessageBox(strError);
}
m_pRecordset->Close();
m_pRecordset=NULL;
break;
default:break;
} //打开记录集 选择表名
}
else{}
}
BOOL CxuqiuVSduixiang4::OpenRecordSet(_RecordsetPtr &recPtr, CString &strSQL)
{
CQFDApp* pApp=(CQFDApp*)AfxGetApp();
//创建记录集对象
m_pRecordset.CreateInstance(__uuidof(Recordset));
//在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
//因为它有时会经常出现一些想不到的错误
try
{
//从数据库中打开表
recPtr->Open(strSQL.AllocSysString(),
pApp->m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch (_com_error e)
{
CString strError;
strError.Format("警告: 打开数据表时发生异常。 错误信息: %s",\
e.ErrorMessage());
AfxMessageBox(strError);
return FALSE;
}
return TRUE;
}
CString CxuqiuVSduixiang4::VariantToCString(const _variant_t &var)
{
CString strValue;
switch (var.vt)
{
case VT_BSTR://字符串
case VT_LPSTR:
case VT_LPWSTR:
strValue = (LPCTSTR)(_bstr_t)var;
break;
case VT_I1://无符号字符
case VT_UI1:
strValue.Format("%d", var.bVal);
break;
case VT_I2://短整型
strValue.Format("%d", var.iVal);
break;
case VT_UI2://无符号短整型
strValue.Format("%d", var.uiVal);
break;
case VT_INT://整型
strValue.Format("%d", var.intVal);
break;
case VT_I4: //整型
case VT_I8: //长整型
strValue.Format("%d", var.lVal);
break;
case VT_UINT://无符号整型
strValue.Format("%d", var.uintVal);
break;
case VT_UI4: //无符号整型
case VT_UI8: //无符号长整型
strValue.Format("%d", var.ulVal);
break;
case VT_VOID:
strValue.Format("%8x", var.byref);
break;
case VT_R4://浮点型
strValue.Format("%.4f", var.fltVal);
break;
case VT_R8://双精度型
strValue.Format("%.8f", var.dblVal);
break;
case VT_DECIMAL: //小数
strValue.Format("%.8f", (double)var);
break;
case VT_CY:
{
COleCurrency cy = var.cyVal;
strValue = cy.Format();
}
break;
case VT_BLOB:
case VT_BLOB_OBJECT:
case 0x2011:
strValue = "[BLOB]";
break;
case VT_BOOL://布尔型
strValue = var.boolVal ? "TRUE" : "FALSE";
break;
case VT_DATE: //日期型
{
DATE dt = var.date;
COleDateTime da = COleDateTime(dt);
strValue = da.Format("%Y-%m-%d %H:%M:%S");
}
break;
case VT_NULL://NULL值
case VT_EMPTY://空
strValue = "";
break;
case VT_UNKNOWN://未知类型
default:
strValue = "UN_KNOW";
break;
}
return strValue;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -