level 2
就是点添加的时候编辑框不要显示数据,点修改的时候要显示选择的数据
2015年11月06日 04点11分
4
level 9
这个你可以做一个添加的框,再做一个修改的框
也可以做成一个,里边定义个public变量,标志是添加还是修改
调用窗体显示之前,先标志一下那个变量
在窗体初始化里边根据标志变量的值,显示或者不显示那些数据就可以了
2015年11月06日 05点11分
5
非常感谢,用第二种方法圆满解决
2015年11月06日 07点11分
level 2
void CAdoHospitalDlg::OnButtonQuery()
{
// TODO: Add your control notification handler code here
UpdateData(true);
CString strSQL,strTmp1,strTmp2;
m_combo1.GetLBText(m_combo1.GetCurSel(),strTmp1);
strTmp2='%'+m_keyword+'%';
strSQL.Format("SELECT * FROM 医生信息表 where 's' LIKE 's'",strTmp1,strTmp2);
ListDocInfo(strSQL);
}
void CAdoHospitalDlg::ListDocInfo(CString strSQL)
{
m_listDocInfo.DeleteAllItems();// 首先清空列表视图中的所有数据
_ConnectionPtr m_pConnection;// 创建连接对象指针
m_pConnection.CreateInstance(__uuidof(Connection));// 创建连接对象实例
try
{
m_pConnection->Open("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=医院数据库.accdb","","",adModeUnknown);
}
catch(_com_error e)
{
AfxMessageBox("数据库连接失败,确认数据库“医院数据库.accdb”是否在当前路径下!");
return;
}
//_RecordsetPtr m_pRecordset;// 创建记录集对象指针
m_pRecordset.CreateInstance(__uuidof(Recordset));//创建记录集对象实例
try
{
m_pRecordset->Open(// 打开记录集对象
_variant_t(strSQL),// 执行strSQL中的SQL语句
m_pConnection.GetInterfacePtr(),// 获取库接库的IDispatch指针
adOpenDynamic,// 动态光标
adLockOptimistic,// 乐观锁定方式
adCmdText// CommandText是文本命令
);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
_variant_t var;
CString strTmp;
for(int i=0;!m_pRecordset->adoEOF;i++)// 判断是否到达记录集末尾
{
var=m_pRecordset->GetCollect("工号");// 获取工号字段的值
strTmp=(LPCSTR)_bstr_t(var);
m_listDocInfo.InsertItem(i,strTmp);
var=m_pRecordset->GetCollect("姓名");// 获取姓名字段的值
strTmp=(LPCSTR)_bstr_t(var);
m_listDocInfo.SetItemText(i,1,strTmp);
var=m_pRecordset->GetCollect("性别");// 获取性别字段的值
strTmp=(LPCSTR)_bstr_t(var);
m_listDocInfo.SetItemText(i,2,strTmp);
var=m_pRecordset->GetCollect("年龄");// 获取年龄字段的值
strTmp=(LPCSTR)_bstr_t(var);
m_listDocInfo.SetItemText(i,3,strTmp);
var=m_pRecordset->GetCollect("职务");// 获取职务字段的值
strTmp=(LPCSTR)_bstr_t(var);
m_listDocInfo.SetItemText(i,4,strTmp);
m_pRecordset->MoveNext();// 记录集指针移动到下一条记录
}
m_pRecordset->Close();// 关闭记录集
m_pRecordset.Release();// 释放记录集对象
m_pRecordset=NULL;
if(m_pConnection->State)
m_pConnection->Close(); // 关闭与数据库的连接
m_pConnection=NULL;
UpdateData(false);
}
2015年11月06日 12点11分
6
level 9
你下断点看看,组 sql之前得到下拉框的字符串了没有
2015年11月06日 12点11分
7