注册完ODBC数据库后,生成MFC ODBC程序时,选择了数据库中的对象后,点击完成就死机了。
2个回答
展开全部
没时间详细说 给你个例子 有时间晚上交流
qq 469392501
void CMemoDBSDlg::OnBtnDelMember()
{
// TODO: Add your control notification handler code here
//获取要删除的成员记录所在的行.
int nItem = m_listMember.GetNextItem(-1, LVNI_SELECTED);
if(nItem == -1){
AfxMessageBox("没有选择要删除的成员");
return;
}
//获取成员败梁ID.
int id = atoi(m_listMember.GetItemText(nItem,0));
TRY{
CString sql;
//从数据库中删除记录.
sql.Format("DELETE member_tab "
"where member_id = %d",id);
TRACE(sql);
m_db.ExecuteSQL(sql);
/庆睁/从列表控件中删除该记录.
m_listMember.DeleteItem(nItem);
}
CATCH(CDBException,ex)
{
AfxMessageBox (ex->m_strError);
AfxMessageBox (ex->m_strStateNativeOrigin);
}
AND_CATCH(CException,e)
{
TCHAR szError[100];
e->GetErrorMessage(szError,100);
AfxMessageBox (szError);
}
END_CATCH
}
void CMemoDBSDlg::OnBtnAddType()
{
// TODO: Add your control notification handler code here
//添誉枯岁加备注类型.
//初始化备注类型对话框实例.
CMemoTypeDlg dlg;
if(dlg.DoModal() == IDOK){
//从对话框中获取新添加的备注类型.
CString strName = dlg.m_strTypeName;
TRY{
CRecordset rs(&m_db);
//获取最大的类型ID值.
rs.Open(CRecordset::dynaset,
"Select max(TYPE_ID) from MEMO_TYPE_TAB");
//初始化新类型ID值为1.
int newTypeID = 1;
//如果数据库已经有类型记录,则新的类型ID为最大类型ID+1
if(!rs.IsEOF()) {
CDBVariant var;
rs.GetFieldValue((short)0, var, SQL_C_SLONG);
if (var.m_dwType != DBVT_NULL)
newTypeID = var.m_iVal + 1;
}
CString sql;
//向数据库中添加新的备忘录类型记录.
sql.Format("Insert into MEMO_TYPE_TAB(TYPE_ID,"
"TYPE_NAME) "
"VALUES("
"%d,'%s')",newTypeID,strName);
TRACE(sql);
m_db.ExecuteSQL(sql);
//向界面中添加记录行.
InsertMemoTypeItem(newTypeID,strName);
}
CATCH(CDBException,ex)
{
AfxMessageBox (ex->m_strError);
AfxMessageBox (ex->m_strStateNativeOrigin);
}
AND_CATCH(CException,e)
{
TCHAR szError[100];
e->GetErrorMessage(szError,100);
AfxMessageBox (szError);
}
END_CATCH
}
}
void CMemoDBSDlg::OnBtnModType()
{
// TODO: Add your control notification handler code here
//获取要修改的类型记录
int nItem = m_listType.GetNextItem(-1, LVNI_SELECTED);
//如果没有选择要修改的纪录,返回.
if(nItem == -1){
AfxMessageBox("没有选择要修改的类型");
return;
}
//获取要修改记录的ID和名称.
int id = atoi(m_listType.GetItemText(nItem,0));
CString name = m_listType.GetItemText(nItem,1);
//初始化备注类型对话框.
CMemoTypeDlg dlg;
//给对话框的变量赋值.
dlg.m_strTypeName = name;
if(dlg.DoModal() == IDOK){
//获取修改后的数据.
CString strName = dlg.m_strTypeName;
TRY{
CString sql;
//更新记录.
sql.Format("UPDATE MEMO_TYPE_TAB SET TYPE_NAME = '%s' "
" WHERE TYPE_ID = %d",strName,id);
TRACE(sql);
m_db.ExecuteSQL(sql);
//修改界面的值.
m_listType.SetItemText(nItem,1,strName);
}
CATCH(CDBException,ex)
{
AfxMessageBox (ex->m_strError);
AfxMessageBox (ex->m_strStateNativeOrigin);
}
AND_CATCH(CException,e)
{
TCHAR szError[100];
e->GetErrorMessage(szError,100);
AfxMessageBox (szError);
}
END_CATCH
}
}
void CMemoDBSDlg::OnBtnDelType()
{
// TODO: Add your control notification handler code here
//获取要删除的记录所在的行.
int nItem = m_listType.GetNextItem(-1, LVNI_SELECTED);
//如果没有选择,返回.
if(nItem == -1){
AfxMessageBox("没有选择要删除的类型");
return;
}
//获取要删除的类型ID
int id = atoi(m_listType.GetItemText(nItem,0));
TRY{
CString sql;
sql.Format("DELETE MEMO_TYPE_TAB "
"where TYPE_ID = %d",id);
TRACE(sql);
//删除类型记录
m_db.ExecuteSQL(sql);
//删除界面中的记录.
m_listType.DeleteItem(nItem);
}
CATCH(CDBException,ex)
{
AfxMessageBox (ex->m_strError);
AfxMessageBox (ex->m_strStateNativeOrigin);
}
AND_CATCH(CException,e)
{
TCHAR szError[100];
e->GetErrorMessage(szError,100);
AfxMessageBox (szError);
}
END_CATCH
}
void CMemoDBSDlg::OnBtnAddMemo()
{
// TODO: Add your control notification handler code here
//初始化备忘录信息对话框.
CMemoInfoDlg dlg;
//获取所有的家庭成员的名称.
for(int i = 0 ; i < m_listMember.GetItemCount() ; i++ )
dlg.m_strMemberArray.Add(m_listMember.GetItemText(i,1)) ;
//获取所有的类型信息.
for(i = 0 ; i < m_listType.GetItemCount() ; i++ )
dlg.m_strTypeArray.Add(m_listType.GetItemText(i,1)) ;
//打开对话框,添加新的记录.
if(dlg.DoModal() == IDOK){
//从对话框中获取记录值.
CString strName = dlg.m_strMember;
CString strType = dlg.m_strMemoType;
CString strHappenDate = dlg.m_oleDate.Format("%Y-%m-%d")
+ " " + dlg.m_oleTime.Format("%H:%M:%S");
CString strOperDate = COleDateTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S");
int isEvent = dlg.m_isEvent;
CString strCost = dlg.m_strCost;
CString strMemo = dlg.m_strMemoInfo;
TRY{
CRecordset rs(&m_db);
CString sql;
//根据成员姓名获取成员ID值.
sql.Format("Select MEMBER_ID from MEMBER_TAB where "
"MEMBER_NAME = '%s'",strName);
rs.Open(CRecordset::dynaset,sql);
int memberID = 1;
if(!rs.IsEOF()) {
CDBVariant var;
rs.GetFieldValue((short)0, var, SQL_C_SLONG);
if (var.m_dwType != DBVT_NULL)
memberID = var.m_iVal;
}
rs.Close();
//根据备忘录类型获取备忘录类型ID.
sql.Format("Select TYPE_ID from MEMO_TYPE_TAB where "
"TYPE_NAME = '%s'",strType);
rs.Open(CRecordset::dynaset,sql);
int typeID = 1;
if(!rs.IsEOF()) {
CDBVariant var;
rs.GetFieldValue((short)0, var, SQL_C_SLONG);
if (var.m_dwType != DBVT_NULL)
typeID = var.m_iVal;
}
rs.Close();
//从SEQ_MEMO_ID序列中获取下一个值.这个值就是新的备忘录ID.
rs.Open(CRecordset::dynaset,
"Select max(MEMO_ID) from MEMO_INFO_TAB");
int memoID = 1;
if(!rs.IsEOF()) {
CDBVariant var;
rs.GetFieldValue((short)0, var, SQL_C_SLONG);
if (var.m_dwType != DBVT_NULL)
memoID = var.m_iVal+1;
}
sql.Format("Insert into MEMO_INFO_TAB(MEMO_ID,"
"MEMBER_ID,OPER_DATE,HAPPEN_DATE,"
"IS_BIGEVENT,EVENT_COST,TYPE_ID,MEMO_TEXT) "
"VALUES("
"%d,%d,'%s'"
",'%s',%d,'%s'"
",%d,'%s')",memoID,memberID,
strOperDate,strHappenDate,isEvent,strCost,typeID,strMemo);
TRACE(sql);
m_db.ExecuteSQL(sql);
//向界面中插入新的纪录.
InsertMemoInfoItem(memoID,strName,strOperDate,strHappenDate,isEvent,strCost,strType,strMemo) ;
}
CATCH(CDBException,ex)
{
AfxMessageBox (ex->m_strError);
AfxMessageBox (ex->m_strStateNativeOrigin);
}
AND_CATCH(CException,e)
{
TCHAR szError[100];
e->GetErrorMessage(szError,100);
AfxMessageBox (szError);
}
END_CATCH
}
}
qq 469392501
void CMemoDBSDlg::OnBtnDelMember()
{
// TODO: Add your control notification handler code here
//获取要删除的成员记录所在的行.
int nItem = m_listMember.GetNextItem(-1, LVNI_SELECTED);
if(nItem == -1){
AfxMessageBox("没有选择要删除的成员");
return;
}
//获取成员败梁ID.
int id = atoi(m_listMember.GetItemText(nItem,0));
TRY{
CString sql;
//从数据库中删除记录.
sql.Format("DELETE member_tab "
"where member_id = %d",id);
TRACE(sql);
m_db.ExecuteSQL(sql);
/庆睁/从列表控件中删除该记录.
m_listMember.DeleteItem(nItem);
}
CATCH(CDBException,ex)
{
AfxMessageBox (ex->m_strError);
AfxMessageBox (ex->m_strStateNativeOrigin);
}
AND_CATCH(CException,e)
{
TCHAR szError[100];
e->GetErrorMessage(szError,100);
AfxMessageBox (szError);
}
END_CATCH
}
void CMemoDBSDlg::OnBtnAddType()
{
// TODO: Add your control notification handler code here
//添誉枯岁加备注类型.
//初始化备注类型对话框实例.
CMemoTypeDlg dlg;
if(dlg.DoModal() == IDOK){
//从对话框中获取新添加的备注类型.
CString strName = dlg.m_strTypeName;
TRY{
CRecordset rs(&m_db);
//获取最大的类型ID值.
rs.Open(CRecordset::dynaset,
"Select max(TYPE_ID) from MEMO_TYPE_TAB");
//初始化新类型ID值为1.
int newTypeID = 1;
//如果数据库已经有类型记录,则新的类型ID为最大类型ID+1
if(!rs.IsEOF()) {
CDBVariant var;
rs.GetFieldValue((short)0, var, SQL_C_SLONG);
if (var.m_dwType != DBVT_NULL)
newTypeID = var.m_iVal + 1;
}
CString sql;
//向数据库中添加新的备忘录类型记录.
sql.Format("Insert into MEMO_TYPE_TAB(TYPE_ID,"
"TYPE_NAME) "
"VALUES("
"%d,'%s')",newTypeID,strName);
TRACE(sql);
m_db.ExecuteSQL(sql);
//向界面中添加记录行.
InsertMemoTypeItem(newTypeID,strName);
}
CATCH(CDBException,ex)
{
AfxMessageBox (ex->m_strError);
AfxMessageBox (ex->m_strStateNativeOrigin);
}
AND_CATCH(CException,e)
{
TCHAR szError[100];
e->GetErrorMessage(szError,100);
AfxMessageBox (szError);
}
END_CATCH
}
}
void CMemoDBSDlg::OnBtnModType()
{
// TODO: Add your control notification handler code here
//获取要修改的类型记录
int nItem = m_listType.GetNextItem(-1, LVNI_SELECTED);
//如果没有选择要修改的纪录,返回.
if(nItem == -1){
AfxMessageBox("没有选择要修改的类型");
return;
}
//获取要修改记录的ID和名称.
int id = atoi(m_listType.GetItemText(nItem,0));
CString name = m_listType.GetItemText(nItem,1);
//初始化备注类型对话框.
CMemoTypeDlg dlg;
//给对话框的变量赋值.
dlg.m_strTypeName = name;
if(dlg.DoModal() == IDOK){
//获取修改后的数据.
CString strName = dlg.m_strTypeName;
TRY{
CString sql;
//更新记录.
sql.Format("UPDATE MEMO_TYPE_TAB SET TYPE_NAME = '%s' "
" WHERE TYPE_ID = %d",strName,id);
TRACE(sql);
m_db.ExecuteSQL(sql);
//修改界面的值.
m_listType.SetItemText(nItem,1,strName);
}
CATCH(CDBException,ex)
{
AfxMessageBox (ex->m_strError);
AfxMessageBox (ex->m_strStateNativeOrigin);
}
AND_CATCH(CException,e)
{
TCHAR szError[100];
e->GetErrorMessage(szError,100);
AfxMessageBox (szError);
}
END_CATCH
}
}
void CMemoDBSDlg::OnBtnDelType()
{
// TODO: Add your control notification handler code here
//获取要删除的记录所在的行.
int nItem = m_listType.GetNextItem(-1, LVNI_SELECTED);
//如果没有选择,返回.
if(nItem == -1){
AfxMessageBox("没有选择要删除的类型");
return;
}
//获取要删除的类型ID
int id = atoi(m_listType.GetItemText(nItem,0));
TRY{
CString sql;
sql.Format("DELETE MEMO_TYPE_TAB "
"where TYPE_ID = %d",id);
TRACE(sql);
//删除类型记录
m_db.ExecuteSQL(sql);
//删除界面中的记录.
m_listType.DeleteItem(nItem);
}
CATCH(CDBException,ex)
{
AfxMessageBox (ex->m_strError);
AfxMessageBox (ex->m_strStateNativeOrigin);
}
AND_CATCH(CException,e)
{
TCHAR szError[100];
e->GetErrorMessage(szError,100);
AfxMessageBox (szError);
}
END_CATCH
}
void CMemoDBSDlg::OnBtnAddMemo()
{
// TODO: Add your control notification handler code here
//初始化备忘录信息对话框.
CMemoInfoDlg dlg;
//获取所有的家庭成员的名称.
for(int i = 0 ; i < m_listMember.GetItemCount() ; i++ )
dlg.m_strMemberArray.Add(m_listMember.GetItemText(i,1)) ;
//获取所有的类型信息.
for(i = 0 ; i < m_listType.GetItemCount() ; i++ )
dlg.m_strTypeArray.Add(m_listType.GetItemText(i,1)) ;
//打开对话框,添加新的记录.
if(dlg.DoModal() == IDOK){
//从对话框中获取记录值.
CString strName = dlg.m_strMember;
CString strType = dlg.m_strMemoType;
CString strHappenDate = dlg.m_oleDate.Format("%Y-%m-%d")
+ " " + dlg.m_oleTime.Format("%H:%M:%S");
CString strOperDate = COleDateTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S");
int isEvent = dlg.m_isEvent;
CString strCost = dlg.m_strCost;
CString strMemo = dlg.m_strMemoInfo;
TRY{
CRecordset rs(&m_db);
CString sql;
//根据成员姓名获取成员ID值.
sql.Format("Select MEMBER_ID from MEMBER_TAB where "
"MEMBER_NAME = '%s'",strName);
rs.Open(CRecordset::dynaset,sql);
int memberID = 1;
if(!rs.IsEOF()) {
CDBVariant var;
rs.GetFieldValue((short)0, var, SQL_C_SLONG);
if (var.m_dwType != DBVT_NULL)
memberID = var.m_iVal;
}
rs.Close();
//根据备忘录类型获取备忘录类型ID.
sql.Format("Select TYPE_ID from MEMO_TYPE_TAB where "
"TYPE_NAME = '%s'",strType);
rs.Open(CRecordset::dynaset,sql);
int typeID = 1;
if(!rs.IsEOF()) {
CDBVariant var;
rs.GetFieldValue((short)0, var, SQL_C_SLONG);
if (var.m_dwType != DBVT_NULL)
typeID = var.m_iVal;
}
rs.Close();
//从SEQ_MEMO_ID序列中获取下一个值.这个值就是新的备忘录ID.
rs.Open(CRecordset::dynaset,
"Select max(MEMO_ID) from MEMO_INFO_TAB");
int memoID = 1;
if(!rs.IsEOF()) {
CDBVariant var;
rs.GetFieldValue((short)0, var, SQL_C_SLONG);
if (var.m_dwType != DBVT_NULL)
memoID = var.m_iVal+1;
}
sql.Format("Insert into MEMO_INFO_TAB(MEMO_ID,"
"MEMBER_ID,OPER_DATE,HAPPEN_DATE,"
"IS_BIGEVENT,EVENT_COST,TYPE_ID,MEMO_TEXT) "
"VALUES("
"%d,%d,'%s'"
",'%s',%d,'%s'"
",%d,'%s')",memoID,memberID,
strOperDate,strHappenDate,isEvent,strCost,typeID,strMemo);
TRACE(sql);
m_db.ExecuteSQL(sql);
//向界面中插入新的纪录.
InsertMemoInfoItem(memoID,strName,strOperDate,strHappenDate,isEvent,strCost,strType,strMemo) ;
}
CATCH(CDBException,ex)
{
AfxMessageBox (ex->m_strError);
AfxMessageBox (ex->m_strStateNativeOrigin);
}
AND_CATCH(CException,e)
{
TCHAR szError[100];
e->GetErrorMessage(szError,100);
AfxMessageBox (szError);
}
END_CATCH
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询